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

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

maynowei2周前 (08-02)技术知识13

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

相关文章

Axure8.0教程:“百度一下,你就知道”搜索首页原型设计

加入人人都是产品经理【起点学院】产品经理实战训练营,BAT产品总监手把手带你学产品百度作为最大的中文搜索引擎,在某种程度上,有点学习google的简约至上的原则,但是给人的感觉还是不够彻底。今天,使用...

出售闲置原型素材来赚钱,上传作品,即可收上万元收入

出售闲置原型素材来赚钱。产品经理每年设计出大量的原型作品和组件、元件库、交互原型模板等作品,如果项目结束,你的原型就失去了作用,而有需求的人却找不到这样的作品。现在我们发现这样一家元件库、原型模板、素...

IT博物馆之Objective-C诞生(micro博物馆)

1984年,Objective-C诞生。设计者:布莱德·考克斯(Brad Cox)、汤姆·洛夫(Tom Love)Objective-C是面向对象的通用、高级编程语言。它扩展了标准的 ANSI C,将...

伪装成抖音国际版Tiktok的短信蠕虫

概述近期监测到一款仿冒Tiktok的短信蠕虫,该短信蠕虫最明显的特点就是针对Android系统版本高于6.0以上的设备,由于Android版本的更新迭代,现在大部分设备已经更新到较高的版本,通过不完全...

有了这份900多页的Android面试指南,你离大厂Offer还远吗?

前言对于大部分程序员来说,一线互联网是的工作经历是毕生的追求,实际上大厂对于学历的要求远远没有我们想象的那么高,近几年来,互联网公司更注重技术,所以提升自身技术水平才是斩获offer的制胜关键。一线互...

Android TabLayout + ViewPager2使用

1、xml文件<!--明细列表--> <com.google.android.material.tabs.TabLayout android:id="@+id/ty_...