Android ExpandableListView 展开列表控件(手机QQ好友列表)


你是否觉得手机QQ上的好友列表那个控件非常棒?  不是.....   那也没关系, 学多一点知识对自己也有益无害。

那么我们就开始吧。

展开型列表控件, 原名ExpandableListView

是普通的列表控件进阶版, 可以自由的把列表进行收缩, 非常的方便兼好看。

首先看看我完成的截图, 虽然界面不漂亮, 但大家可以自己去修改界面。

Android 

该控件需要一个主界面XML  一个标题界面XML及一个列表内容界面XML

首先我们来看看  mian.xml 主界面

//该界面非常简单, 只要一个ExpandableListView即可

  1. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="fill_parent"  
  4.     android:orientation="vertical" >  
  5.   
  6.     <ExpandableListView   
  7.         android:id="@id/android:list"  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="fill_parent"  
  10.         />  
  11. </LinearLayout>  

groups.xml   该界面是父标题界面

我们只要放上一个要显示出来的标题TextView控件上去即可

  1. <LinearLayout  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6. >  
  7.     <TextView  
  8.         android:id="@+id/textGroup"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="fill_parent"  
  11.         android:paddingLeft="40px"  
  12.         android:paddingTop="6px"  
  13.         android:paddingBottom="6px"  
  14.         android:textSize="15sp"  
  15.         android:text="No data"  
  16.     />  
  17.   
  18. </LinearLayout>  

childs.xml  是子控件, 直接显示列表内容

  1. <LinearLayout  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6. >  
  7.     <TextView    
  8.         android:id="@+id/textChild"  
  9.         android:layout_width="fill_parent"   
  10.         android:layout_height="fill_parent"   
  11.         android:paddingLeft="60px"  
  12.         android:paddingTop="10px"  
  13.         android:paddingBottom="10px"  
  14.         android:textSize="20sp"  
  15.         android:text="No Data"  
  16. />  
  17.   
  18. </LinearLayout>  
  • 1
  • 2
  • 3
  • 下一页

相关内容