Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

android - Using LinearLayout instead of RecyclerView in DrawerLayout

Since I'm using a fixed menu for the navigation drawer I tried to use LinearLayout in DrawerLayout's second child instead of RecyclerView/ListView to make it easier to code. But the result is a full-screen linearlayout. Is there any way to use a regular view (like linearlayout) in DrawerLayout?

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello world"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Bye world"/>
</LinearLayout>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Any View can act as a drawer in a DrawerLayout. For the DrawerLayout to recognize a View as a drawer, it must have a layout_gravity attribute set to left/right or start/end, depending on which vertical edge you want the drawer attached to.

The drawer's layout_height is normally match_parent, so that the drawer spans the full height of the DrawerLayout, and its layout_width is normally an exact measure - e.g., 240dp - to keep a consistent width, independent of its contents.

Additionally, the drawer View must be listed last within the DrawerLayout to maintain the correct z-order, otherwise it will be covered by the content View and won't receive click events.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...