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

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

maynowei3周前 (08-02)技术知识15

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 RP设计伸缩导航、遮罩弹窗、返回顶部的方法

以下几小教程使用的是Axure的动态面板来实现,内容简单,适合菜鸟查阅,老鸟可飘过,顺便帮忙点个赞哈/偷笑。一.伸缩/隐藏导航栏例如:鼠标移动到一级导航上,二级导航会下拉方式显示1.打开Axure,拖...

高效办公,你值得拥有之原型工具AXURE篇

简介 Axure RP是美国Axure Software Solution公司旗舰产品,是一个专业的快速原型设计工具,让负责定义需求和规格、设计功能和界面的专家能够快速创建应用软件或Web网站的线框图...

Objective-C的本质(objective-c的特点)

我们平时编写的Objective-C代码,底层实现其实都是C\C++代码,所以Objective-C的面向对象都是基于C\C++的数据结构实现的OC对象的本质Objective-C的对象、类主要是基于...

惊现!iOS 16.5 kfd 漏洞利用,成功隐藏 Dock 栏

最近!kfd漏洞比较活跃,进展也是很顺利,今天就有大神成功使用 kfd 漏洞实现隐藏 Dock 栏,到底怎么回事?请继续往下看。-- kfd 漏洞说明 --kfd漏洞适合在 iOS 16.2 - 16...

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

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

webview 渲染机制:硬件加速方式渲染的Android Web

webview 渲染是什么?webview 渲染是用于展现web页面的控件; webview 可以内嵌在移动端,实现前端的混合式开发,大多数混合式开发框架都是基于 webview 模式进行二次开发的w...