歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android ExpandableListView 展開列表控件(手機QQ好友列表)

Android ExpandableListView 展開列表控件(手機QQ好友列表)

日期:2017/3/1 10:56:37   编辑:Linux編程

你是否覺得手機QQ上的好友列表那個控件非常棒? 不是..... 那也沒關系, 學多一點知識對自己也有益無害。

那麼我們就開始吧。

展開型列表控件, 原名ExpandableListView

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

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

該控件需要一個主界面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. <ExpandableListView
  6. android:id="@id/android:list"
  7. android:layout_width="fill_parent"
  8. android:layout_height="fill_parent"
  9. />
  10. </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. </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. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved