使用DrawerLayout組件實現(xiàn)側滑抽屜的功能
DrawerLayout組件同樣是V4包中的組件,也是直接繼承于ViewGroup類,所以這個類也是一個容器類。使用DrawerLayout可以輕松的實現(xiàn)抽屜效果,使用DrawerLayout的步驟有以下幾點:
1)在DrawerLayout中,第一個子View必須是顯示內容的view,并且設置它的layout_width和layout_height屬性是match_parent.
2)第二個view是抽屜view,并且設置屬性layout_gravity="left|right",表示是從左邊滑出還是右邊滑出。設置它的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>
實現(xiàn)的效果:

以上所述是小編給大家介紹的使用DrawerLayout組件實現(xiàn)側滑抽屜的功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
Android studio實現(xiàn)PopupWindow彈出框效果
這篇文章主要為大家詳細介紹了Android studio實現(xiàn)PopupWindow彈出框效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-10-10

