ExpandableListView分割线处理
来源:互联网 发布:开发题库软件思路 编辑:程序博客网 时间:2024/06/06 01:50
本人是android开发新手,现在开始记录在实际开发中遇到的问题,希望有一天成为自己崇拜的大牛。
ExpandableListView
在一个项目中碰见了需要分组展示数据的需求,类似于QQ分组,如下:
于是第一 反应就是使用ExpandableListView控件,但是问题来了,需求是父类列表之间的分割线是自己定义的样子,子项之间没有分割线。
android:divider="@drawable/list_item_divider"
结果发现只要setDivider之后,父列表和子项之间都没有分割线了,网上查了很久,发现都没什么好的办法,只能用setChildDivider把子项分割线设置为空,父列表之间的分割线一直没办法改变,当我想着去重写这个控件的时候突然想到了可以把父列表和子列表的分割线都设置为空,然后在父列表的布局文件中写个分割线代码如下:
fragment_contract.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bg_color" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="@dimen/activity_layout_48" android:background="@color/white"> <ImageView android:id="@+id/call_log" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="@dimen/activity_layout_8" android:src="@drawable/calling" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="@dimen/activity_layout_100" android:layout_marginTop="@dimen/activity_layout_8" android:background="@color/white" android:gravity="center"> <GridView android:id="@+id/address_book_gv" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="@dimen/activity_layout_15" android:numColumns="3"></GridView> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="@dimen/activity_layout_8" android:background="@color/white"> <TextView android:id="@+id/address_book_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/activity_layout_8" android:layout_marginTop="@dimen/activity_layout_10" android:text="翰中集团" android:textColor="@color/black" android:textSize="@dimen/textSize_16" /> <ExpandableListView android:id="@+id/address_list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/address_book_group" android:layout_marginTop="@dimen/activity_layout_11" android:divider="@null" ></ExpandableListView> </RelativeLayout></LinearLayout>
注意将分割线设置为空
android:divider="@null"
下面是父类列表的布局
address_group_itme.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/ll" android:layout_width="match_parent" android:layout_height="@dimen/activity_layout_56" android:gravity="center|left" android:orientation="horizontal"> <ImageView android:id="@+id/logo" android:layout_width="@dimen/activity_layout_35" android:layout_height="@dimen/activity_layout_35" android:layout_marginLeft="@dimen/activity_layout_8" android:src="@drawable/logo" /> <TextView android:id="@+id/account_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/activity_layout_7" android:text="haha" android:textColor="@color/black" android:textSize="@dimen/textSize_16" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="@dimen/activity_layout_0.5" android:layout_below="@id/ll" android:background="@drawable/list_item_divider" /></RelativeLayout>
list_item_divider.xml
<?xml version="1.0" encoding="utf-8"?><inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@color/color_line" android:insetLeft="@dimen/activity_layout_51"></inset>
写个高度为0.5dp的View当做分割线,在 getGroupView里面设置address_group_itme.xml 这个布局就行了。
最终效果:
第一次写博客,不知道怎么写比较好,有不明白的同学,可以加我QQ:1318387070一起学习讨论。
0 0
- ExpandableListView分割线处理
- 自定义ExpandableListView分割线
- ExpandableListView 分割线颜色设置
- ListView与ExpandableListView设置分割线 divider
- ListView与ExpandableListView设置分割线 divider
- 设置ExpandableListView不显示分割线
- ExpandableListView去掉里头的分割线
- ExpandableListView设置分割线的颜色
- ListViw ExpandableListView 在item设置分割线
- ExpandableListView去掉item分割线的方法
- UITableView分割线处理
- AutoCompleteTextView 分割线处理
- Recyclerview使用flexibledivider处理分割线
- 分割线
- -------------- 分割线 ------------
- 分割线
- --------------------------------------------分割线
- ----------------------------------------------------------------------------------分割线
- HCIE-Cloud学习心得(1)——认识华为FusionSphere
- 菜鸟学Word
- 2016年7月18日考试总结
- 1小时内打造你自己的PHP MVC框架
- PHP安装后访问 index.php 出现源码
- ExpandableListView分割线处理
- linux中dig 命令解释
- <疯狂Android讲义>阅读笔记(4)
- Android Studio中进行签名打包
- swift-tabBar
- 读书摘要——第六章
- Android中LinearLayout布局的Weight属性详解
- wifi 玩转 wifi
- Android tips(九)-->Android录屏与转化gif图