Android UI Libs之ExpandableLayout

Android UI Libs之ExpandableLayout


1. 說明


ExpandableLayout,顧名思義,可擴(kuò)展的布局,是一個(gè)可以幫助我們實(shí)現(xiàn)折疊功能的第三方庫,折疊時(shí),只顯示頭部,打開時(shí),顯示頭部與內(nèi)容。

2. 配置


在模塊中添加依賴:compile 'com.github.traex.expandablelayout:library:1.2.2'

因?yàn)樘砑右蕾嚨腶ar文件中設(shè)置了應(yīng)用程序圖標(biāo),所以我們要在清單文件AndroidManifest.xmlmanifest里面添加xmlns:tools="http://schemas.android.com/tools",application里面面添加上tools:replace="android:icon",不然會(huì)有沖突。

3. 使用方法


擴(kuò)展單個(gè)內(nèi)容時(shí)使用ExpandableLayoutItem,擴(kuò)展ListView時(shí)使用ExpandableLayoutListView。

1. 擴(kuò)展單個(gè)內(nèi)容


擴(kuò)展單個(gè)內(nèi)容時(shí)的xml布局,expandable:headerLayout代表頭部,expandable:contentLayout代表內(nèi)容
xmlns:expandable="http://schemas.android.com/apk/res-auto"

    <com.andexert.expandablelayout.library.ExpandableLayout
        android:id="@+id/first"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        expandable:headerLayout="@layout/view_header"
        expandable:contentLayout="@layout/view_content"
        android:background="#e74c3c"/>  

2. 擴(kuò)展Listview


擴(kuò)展ListView時(shí)的xml布局,expandable:headerLayout代表頭部,expandable:contentLayout代表內(nèi)容

    <com.andexert.expandablelayout.library.ExpandableLayoutListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </com.andexert.expandablelayout.library.ExpandableLayoutListView>  

ListView中item對(duì)應(yīng)的xml布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:expandable="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.andexert.expandablelayout.library.ExpandableLayoutItem
        android:id="@+id/row"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        expandable:headerLayout="@layout/view_header"
        expandable:contentLayout="@layout/view_content"
        android:background="#e74c3c"/>
</LinearLayout>  

java文件中的相關(guān)代碼:

    private String[] array={"微信公眾號(hào)","Android技術(shù)漫談","Android","Android開發(fā)"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.header_text, array);
        final ExpandableLayoutListView expandableLayoutListView = (ExpandableLayoutListView) findViewById(R.id.list_view);
        expandableLayoutListView.setAdapter(arrayAdapter);
    }  

注意:如果ExpandableLayoutListView中的item中有EditView,那么ExpandableLayoutListView要設(shè)置android:windowSoftInputMode="adjustPan"來阻止自身的重繪與item的關(guān)閉

程序源代碼下載:https://github.com/lavor-zl/UILibs

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,881評(píng)論 25 709
  • 太長(zhǎng)了,還是轉(zhuǎn)載吧...今天在看博客的時(shí)候,無意中發(fā)現(xiàn)了@Trinea在GitHub上的一個(gè)項(xiàng)目Android開源...
    龐哈哈哈12138閱讀 20,383評(píng)論 3 283
  • 春和日月,風(fēng)暖園林。冬季的氣溫一日疊著一日,終于攢成了一個(gè)草長(zhǎng)鶯飛的春天。 周末早晨醒來,迫不及待地掀開窗簾,又是...
    _清澄_閱讀 590評(píng)論 6 6
  • 蒲甘,位于緬甸中部區(qū)域,坐落在伊洛瓦底河中游左岸部分,是緬甸著名的宗教古城,也是東南亞最重要的佛教遺址之一。 蒲甘...
    玉珠陽光閱讀 1,589評(píng)論 0 0
  • 未來不止是說說。它很艱辛。兩個(gè)人在一起的未來,會(huì)比一個(gè)人艱辛很多。這個(gè),我是知道的,而且從來很清晰的知道。其實(shí)單身...
    靜聽歲月閱讀 257評(píng)論 1 2

友情鏈接更多精彩內(nèi)容