Android UI Libs之ExpandableLayout
来源:互联网 发布:如何评价张德芬 知乎 编辑:程序博客网 时间:2024/06/09 16:59
Android UI Libs之ExpandableLayout
1. 说明
ExpandableLayout,顾名思义,可扩展的布局,是一个可以帮助我们实现折叠功能的第三方库,折叠时,只显示头部,打开时,显示头部与内容。
2. 配置
在模块中添加依赖:compile 'com.github.traex.expandablelayout:library:1.2.2'
因为添加依赖的aar文件中设置了应用程序图标,所以我们要在清单文件AndroidManifest.xml
的manifest
里面添加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的关闭
程序源代码下载,我的github仓库:https://github.com/lavor-zl/UILibs
欢迎关注我的简书专题:Android技术漫谈
欢迎关注我的微信公众号:Android技术漫谈
- Android UI Libs之ExpandableLayout
- Android UI Libs之CircleImageView
- Android UI Libs之AndroidSwipeLayout
- Android UI Libs之ExplosionField
- Android UI Libs之android-viewbadger
- Android UI Libs之android-gif-drawable
- Android UI Libs之shimmer-android
- Android UI Libs之android-stackblur模糊照片
- Android ExpandableLayout伸缩隐藏显示布局
- android项目框架中libs之**.so
- Android ExpandableLayout:一种可伸缩扩展的Layout
- Android目录Frameworks下base/libs/ui/EventHub.cpp中加键盘布局文件名称的注释
- Android lib or libs?
- Android UI 之FrameLayout(-)
- Android UI之菜单
- Android--UI之AutoCompleteTextView
- Android--UI之ProgressBar
- Android--UI之ProgressBar
- 程序员那点事--你懂的
- 当遇到算法时的解决方法
- 正则表达式、实例
- $.ajax()方法参数详解
- Android6.0编译时out目录下文件无法自动生成问题解决方案
- Android UI Libs之ExpandableLayout
- 写给医院管理平台的一封信
- linux重定向 case when嵌套 2016.06.14回顾
- ubuntu下eclipse中配置tomcate7
- 登录用户缓存试验
- Android入门--Spinner 与setDropDownViewResource自定义下拉菜单
- 开发平台介绍篇
- 改变条标题栏透明度在6.0上的问题
- 百度UEditor粘贴或插入的表格不显示边框的解决办法