使用DrawerLayout組件實(shí)現(xiàn)側(cè)滑抽屜的功能
DrawerLayout組件同樣是V4包中的組件,也是直接繼承于ViewGroup類,所以這個(gè)類也是一個(gè)容器類。使用DrawerLayout可以輕松的實(shí)現(xiàn)抽屜效果,使用DrawerLayout的步驟有以下幾點(diǎn):
1)在DrawerLayout中,第一個(gè)子View必須是顯示內(nèi)容的view,并且設(shè)置它的layout_width和layout_height屬性是match_parent.
2)第二個(gè)view是抽屜view,并且設(shè)置屬性layout_gravity="left|right",表示是從左邊滑出還是右邊滑出。設(shè)置它的layout_height="match_parent"
例子:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawerlayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="content" /> <ListView android:id="@+id/listview" android:layout_width="80dp" android:layout_height="match_parent" android:layout_gravity="left" android:background="#FFB5C5" /> </android.support.v4.widget.DrawerLayout>
實(shí)現(xiàn)的效果:
以上所述是小編給大家介紹的使用DrawerLayout組件實(shí)現(xiàn)側(cè)滑抽屜的功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Android ListView數(shù)據(jù)的分批顯示功能
本文通過實(shí)例代碼給大家分享了Android ListView數(shù)據(jù)的分批顯示功能,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友參考下吧2017-04-04Android中FoldingLayout折疊布局的用法及實(shí)戰(zhàn)全攻略
這篇文章主要介紹了Android中FoldingLayout折疊布局的用法及實(shí)例,通過FoldingLayout我們可以制作出炫酷的菜單折疊效果,文中的例子講解得非常詳細(xì),需要的朋友可以參考下2016-02-02Android 自定義ListView實(shí)現(xiàn)QQ空間界面(說說內(nèi)包含圖片、視頻、點(diǎn)贊、評(píng)論、轉(zhuǎn)發(fā)功能)
這篇文章主要介紹了Android 自定義ListView實(shí)現(xiàn)QQ空間界面,qq空間說說內(nèi)包含圖片、視頻、點(diǎn)贊、評(píng)論、轉(zhuǎn)發(fā)功能,需要的朋友可以參考下2019-12-12Flutter有無狀態(tài)類與State及生命周期詳細(xì)介紹
這篇文章主要介紹了Flutter無狀態(tài)類、有狀態(tài)類、State、生命周期,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-09-09