> 本讲内容:ExpandableListView,ExpandableListActivity 可扩展列表 二级列表 手风琴效果accordion 本讲源代码下载: ![]() 点击一级列表,展开下一级: 点击二层列表(嵌套的列表)的某一项: 下面我们来看代码: 1、新建一个项目 Lesson43_ExpandableListView 2、main.xml 的内容如下: - <?xml version="1.0" encoding="utf-8"?>
<linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<expandablelistview android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@id/android:list">
</expandablelistview>
</linearlayout>
复制代码 请注意ExpandableListView标签中id的写法是固定的@id/android:list,因为我们这里用的是ExpandableListActivity,而ExpandableListActivity代码里写死了要寻找的UI元素是它,这和我们以前讲的很多特殊的Activity是一样的,这里再稍作提醒。3、MainActivity.java的代码如下,解释在注释里: 4、编译并运行程序即可看到上面的效果。那么本节课就到这里了,Android中很多内容就像本节的ExpandableListView一样讨厌,来,我们一起鄙视一下^_^
</div |