Android之ExpandableListView的各种效果(默认展开不合闭,自定义父栏目及箭头控制)
2018-03-22 11:14
621 查看
1. 设置ExpandableListView 默认是展开的:
先实例化exListView (ExpandableListView所有数据齐全后可用,否则报错)
2. 去掉ExpandableListView 默认的箭头
用到ExpandableListView时有个箭头图标系统自带的在你自定义布局也不能去掉只要设置一个属性即可,如下:
也可以自定义(但是位置还是在那个地方不推荐)如下:
首先,自定义一个expandablelistviewselector.xml文件,具体内容如下: Java代码 加一句代码如下:
1)首先ExpandableListViewelistview; elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉, 2)在自定义的继承自BaseExpandableListAdapter的adapter中有一个方法
expandablelistview响应onGroupClick监听:设置expandablelistview.setOnGroupClickListener()
折叠和展开事件,可以设置setOnGroupCollapseListener和setOnGroupExpandListener
ExpandableListView中包含多个group,想要展开一个group时,其他group都关闭:
3)expandablelistview的Group点击事件,onGroupClick的返回值false展开,true不展开(如果配合默认展开,就会固定展开不收缩)按 Ctrl+C 复制代码
先实例化exListView (ExpandableListView所有数据齐全后可用,否则报错)
exListView.setAdapter(exlvAdapter); //遍历所有group,将所有项设置成默认展开 intgroupCount = exListView.getCount(); for (inti=0; i<groupCount; i++) { exListView.expandGroup(i); };
2. 去掉ExpandableListView 默认的箭头
用到ExpandableListView时有个箭头图标系统自带的在你自定义布局也不能去掉只要设置一个属性即可,如下:
settingLists.setGroupIndicator(null);此处就是设置自定义的箭头图标的。置空则没有了。
也可以自定义(但是位置还是在那个地方不推荐)如下:
首先,自定义一个expandablelistviewselector.xml文件,具体内容如下: Java代码 加一句代码如下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_expanded="true" android:drawable="@drawable/expandablelistviewindicatordown" /> <item android:drawable="@drawable/expandablelistviewindicator" /> </selector>
settingLists.setGroupIndicator(this.getResources().getDrawable(R.layout.expandablelistviewselector));或xml设置:
android:groupIndicator="@drawable/groupIndicator_selector"3. 将默认的箭头修改到右边显示:
1)首先ExpandableListViewelistview; elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉, 2)在自定义的继承自BaseExpandableListAdapter的adapter中有一个方法
/** * 父类view */ @Override ublic View getGroupView(intgroupPosition, booleanisExpanded, View convertView, ViewGroup parent) { Log.i("zhaoxiong","parent view"); LinearLayoutparentLayout=(LinearLayout) View.inflate(context, R.layout.wowocoupons_parent_item, null); TextViewparentTextView=(TextView)parentLayout.findViewById(R.id.parentitem); parentTextView.setText(parentlist.get(groupPosition)); ImageViewparentImageViw=(ImageView) parentLayout.findViewById(R.id.arrow); //判断isExpanded就可以控制是按下还是关闭,同时更换图片 if(isExpanded){ parentImageViw.setBackgroundResource(R.drawable.arrow_down); }else{ parentImageViw.setBackgroundResource(R.drawable.arrow_up); } return parentLayout; }
expandablelistview响应onGroupClick监听:设置expandablelistview.setOnGroupClickListener()
折叠和展开事件,可以设置setOnGroupCollapseListener和setOnGroupExpandListener
ExpandableListView中包含多个group,想要展开一个group时,其他group都关闭:
exList.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { for (int i = 0; i < getData().size(); i++) { if (groupPosition != i) { exList.collapseGroup(i); } } } });
3)expandablelistview的Group点击事件,onGroupClick的返回值false展开,true不展开(如果配合默认展开,就会固定展开不收缩)按 Ctrl+C 复制代码
相关文章推荐
- Android之ExpandableListView的各种效果(默认展开不合闭,自定义父栏目及箭头控制)
- Android记录11-控制ExpandableListView展开和关闭
- ExpandableListView去掉默认箭头和互斥展开
- Android记录13--控制ExpandableListView某一项点击不展开
- [Android]expandablelistview默认展开以及记录已展开或关闭的子布局
- ExpandableListView 去掉默认箭头 和 有按钮的时候无法展开
- 【Android】ExpandableListView 默认展开和不可点击
- ExpandableListView去掉默认箭头和互斥展开
- android-控制ExpandableListView某一项点击不展开
- Android记录11-控制ExpandableListView展开和关闭
- Android的ExpandableListView的动画展开效果和使用traceview的性能优化
- 【Android】ExpandableListView 默认展开
- Android之ExpandableListView的属性(展开,闭合,箭头)
- Android - ExpandableListView的group里添加button后不能展开的解决方法
- Android ListView 侧滑效果实现(滑动展开、滑动删除)
- 【Android界面实现】listview中item的各种进入效果实现
- Android ListView 侧滑效果实现(滑动展开、滑动删除)
- 怎么去除android listview的默认点击效果
- Android中替换ExpandableListView控件前面的箭头图标
- android expandablelistview 展开动画