具人同行,山海经 白话文,京华烟云小说
drawerlayout组件同样是v4包中的组件,也是直接继承于viewgroup类,所以这个类也是一个容器类。使用drawerlayout可以轻松的实现抽屉效果,使用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>
实现的效果:
以上所述是小编给大家介绍的使用drawerlayout组件实现侧滑抽屉的功能,希望对大家有所帮助
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android studio 解决logcat无过滤工具栏的操作
Android Studio 恢复小窗口停靠模式(Docked Mode)
Android studio保存logcat日志到本地的操作
Android Studio快捷键生成TAG、Log.x日志输出介绍
网友评论