很多朋友可能在android开发中,用过ExpandableListView这个组件,这个组件功能强大,比传统的ListView有好多优势。然而在开发中,我相信有好多人,包括我个人都会遇到下面的一些问题:
1。如何替换ExpandableListView的默认箭头
解决方法:在配置文件中有个android:groupIndicator属性,将其设置为:你的selector,例如:android:groupIndicator="@drawable/lt_expandablelistviewselector"
lt_expandablelistviewselector为:
- <?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/lt_open2" />
- <item android:drawable="@drawable/lt_norml2" />
- </selector>
<?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/lt_open2" />
<item android:drawable="@drawable/lt_norml2" />
</selector>
lt_open2和lt_norml2分别是两张不同状态的图片
ExpandableListView的整个布局
- <ExpandableListView
- android:divider="@drawable/lt_listview_line"
- android:childDivider="@drawable/lt_listview_line"
- android:cacheColorHint="#f5f5f5"
- android:background="#f5f5f5"
- android:id="@+id/citylist"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:listSelector="@drawable/lt_imglistselector"
- android:groupIndicator="@drawable/lt_expandablelistviewselector"
- />
<ExpandableListView
android:divider="@drawable/lt_listview_line"
android:childDivider="@drawable/lt_listview_line"
android:cacheColorHint="#f5f5f5"
android:background="#f5f5f5"
android:id="@+id/citylist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@drawable/lt_imglistselector"
android:groupIndicator="@drawable/lt_expandablelistviewselector"
/>
具体你要加载哪些数据,和哪些内容显示在ExpandableListView上,自由发挥吧,o(∩_∩)o 哈哈