当前位置:首页 > 技术知识 > 正文内容

Android让视图折叠(安卓叠加视图设置)

maynowei10个月前 (08-02)技术知识210

Android UI Libs之ExpandableLayout

1. 说明

ExpandableLayout,顾名思义,可扩展的布局,是一个可以帮助我们实现折叠功能的第三方库,折叠时,只显示头部,打开时,显示头部与内容。

2. 配置

在模块中添加依赖:compile '
com.github.traex.expandablelayout:library:1.2.2'

因为添加依赖的aar文件中设置了应用程序图标,所以我们要在清单文件AndroidManifest.xmlmanifest里面添加xmlns:tools="
http://schemas.android.com/tools"
,application里面面添加上tools:replace="android:icon",不然会有冲突。

3. 使用方法

扩展单个内容时使用ExpandableLayoutItem,扩展ListView时使用ExpandableLayoutListView

1. 扩展单个内容

扩展单个内容时的xml布局,expandable:headerLayout代表头部,expandable:contentLayout代表内容

xmlns:expandable="http://schemas.android.com/apk/res-auto"

<com.andexert.expandablelayout.library.ExpandableLayout

android:id="@+id/first"

android:layout_width="match_parent"

android:layout_height="wrap_content"

expandable:headerLayout="@layout/view_header"

expandable:contentLayout="@layout/view_content"

android:background="#e74c3c"/>

2. 扩展Listview

扩展ListView时的xml布局,expandable:headerLayout代表头部,expandable:contentLayout代表内容

<com.andexert.expandablelayout.library.ExpandableLayoutListView

android:id="@+id/list_view"

android:layout_width="match_parent"

android:layout_height="match_parent">

</com.andexert.expandablelayout.library.ExpandableLayoutListView>

ListView中item对应的xml布局文件如下:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:expandable="http://schemas.android.com/apk/res-auto"

android:orientation="vertical" android:layout_width="match_parent"

android:layout_height="match_parent">

<com.andexert.expandablelayout.library.ExpandableLayoutItem

android:id="@+id/row"

android:layout_width="match_parent"

android:layout_height="wrap_content"

expandable:headerLayout="@layout/view_header"

expandable:contentLayout="@layout/view_content"

android:background="#e74c3c"/></LinearLayout>

java文件中的相关代码:

private String[] array={"微信公众号","Android技术漫谈","Android","Android开发"}; @Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.header_text, array); final ExpandableLayoutListView expandableLayoutListView = (ExpandableLayoutListView) findViewById(R.id.list_view);

expandableLayoutListView.setAdapter(arrayAdapter);

}

注意:如果ExpandableLayoutListView中的item中有EditView,那么ExpandableLayoutListView要设置
android:windowSoftInputMode="adjustPan"
来阻止自身的重绘与item的关闭

程序源代码下载:
https://github.com/lavor-zl/UILibs

欢迎关注我的微信公众号:Android技术漫谈

相关文章

2018年度回顾:挖矿木马为什么会成为病毒木马黑产的中坚力量

一、概述根据腾讯御见威胁情报中心监测数据,2018年挖矿木马样本月产生数量在百万级别,且上半年呈现快速增长趋势,下半年上涨趋势有所减缓。由于挖矿的收益可以通过数字加密货币系统结算,使黑色产业变现链条十...

机器人需求驱动导航新SOTA,成功率提升15%!浙大&amp;vivo联手打造

CogDDN团队 投稿量子位|公众号QbitAI让机器人像人一样边看边理解,来自浙江大学和vivo人工智能实验室的研究团队带来了新进展。正如视频所展示的,机器人在复杂的室内环境中不仅能自主探索,还具备...

不需安装oracleclient连接oracle数据库方案

在Oracle官方发布ODP.net之前,我们通常使用微软的System.data.OracleClient进行Oracle数据库操作,它的缺点是必须要装Oracle客户端OracleClient,如...

Navicat Premium 连接 Oracle 数据库

Navicat Premium是一个可多重连接的数据库管理工具,它可让你以单一程序同時连接到 MySQL、SQLite、Oracle 及 PostgreSQL 数据库,让管理不同类型的数据库更加方便。...

Google前工程主管“入住”Oracle(google公司前台)

ZDNet至顶网服务器频道 10月11日 新闻消息:Oracle 已聘用了前 Snapchat 和 Google 工程部主管 Peter Magnusson,其主要的职责是运行一个被重新调整过的 of...

Oracle高级数据库特性揭秘:存储过程、触发器与权限管理

当谈论Oracle高级数据库特性时,存储过程和函数、触发器、权限管理和安全性以及数据库连接和远程访问是关键概念。下面我将为每个主题提供详细的解释,并附上高质量示例。存储过程和函数: 存储过程和函数是预...