歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android之帶group指示器的ExpandableListView

Android之帶group指示器的ExpandableListView

日期:2017/3/1 9:57:21   编辑:Linux編程

我們都知道Android缺省的ExpandableListView的group header無法固定在界面上,當向下滾動後,不能對當前顯示的那些child 指示出它們歸屬於哪個group,在網上搜了很多關於仿手機QQ好友分組效果的ExpandableListView,發現都不盡如意,於是乎在別人的基礎上改進了一點點,其實原理還是差不多的,只是增加了往上擠出去的動畫效果,而且更加簡單,只不過還是沒有完全到達跟QQ一樣的效果,希望有高手能實現更加逼真的效果,下面我們先看看效果圖:

我這裡沒有把ExpandableListView獨立出來形成一個新的控件,跟網上很多朋友一樣,監聽OnScrollListener事件,當group不是在第一個位置時,就把我們頭部的那個indicator顯示出來,並且讓它的view跟當前child所在group的view一樣的,然後再增加一個點擊關閉組的事件,即達到了簡單的仿QQ好友分組的效果。

下面我們先來看看主要的布局文件:main.xml,下面那個topGroup的FrameLayout就是我們的指示器。

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <ExpandableListView
  6. android:id="@+id/expandableListView"
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent">
  9. </ExpandableListView>
  10. <FrameLayout
  11. android:id="@+id/topGroup"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:orientation="vertical">
  15. </FrameLayout>
  16. </FrameLayout>
Copyright © Linux教程網 All Rights Reserved