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

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

maynowei11个月前 (08-02)技术知识227

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技术漫谈

相关文章

Axure操刀微信H5页面之《人际沟通风格测试》的制作过程

来人人都是产品经理【起点学院】,BAT实战派产品总监手把手系统带你学产品、学运营。在之前的文章中我就讲过用Axure制作H5页面(再次声明Axure输出的html文件可能并非基于html5),在H5制...

B端产品设计之业务设计(b端产品ui设计)

编辑导语:在这篇文章里,作者从解决方案设计、业务流程设计、产品功能设计三个方面,分析了如何进行B端产品的业务设计,感兴趣的小伙伴们一起来看一下吧。前篇文章讲了业务梳理,还没看过的同学可以先看看前篇文章...

Objective C interface(objective什么意思)

在Objective C里面,interface基本可以理解为其他语言里面的class。当然也有些不同。首先我们可以新建一个Objective-C的file。这里我们添加一个MyClass.m和一个M...

[三菱PLC] 用&quot;C语言&quot;玩转PLC,三菱PLC使用ST语言超详细教程

ST语言,全称为结构化文本(Structured Text),是一种高级编程语言,专为工业自动化和控制系统设计。我们学习PLC一般是用梯形图,梯形图学会后,学习SFC,但是我发现梯形图和SFC虽然简单...

如何在Go中同步线程(go语言同步锁)

单线程代码已经带来头痛。添加第二个线程,就是从基础头痛升级了。解决方案?互斥锁:线程和数据的交通警察。一旦你理解了它们,线程同步就变成了第二本能,语言无关。在C++和Go中工作,我遇到过所有常见的混乱...

python-oracledb——利用python连接Oracle数据库的好用方法

这篇文章最早发布在CSDN了,最近想尝试使用一下头条,重新转移过来了。背景介绍之前使用的数据库一直是MySql,偶尔使用PostgreSQL,都是利用的数据库连接池使用;最近需要在Oracle数据库取...