4

我一直在尝试制作DrawerLayout一个在. 问题是和在视图顶部重叠,到目前为止,我所有向下移动的努力都失败了。ViewPagerLinearLayoutDrawerLayoutViewPagerLinearLayoutLinearLayout

XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp" >

            <android.support.v4.view.PagerTabStrip
                android:id="@+id/tabstrip"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </android.support.v4.view.ViewPager>

        <LinearLayout
            android:id="@+id/linear_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@id/base_activity_viewpager"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textAppearance="@android:style/TextAppearance.Medium"
                android:textIsSelectable="false" />
        </LinearLayout>

        <!-- Naviagtion drawer -->

        <ListView
            android:id="@+id/drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="#111"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>

我尝试在 linear_layout 中添加一些东西:

  1. android:layout_gravity="bottom"(导致 IllegalStateException)
  2. android:layout_below="@id/viewpager"
  3. android:layout_alignparentbottom="true"

但是所有这些值似乎都被忽略了,甚至改变android:layout_widthLinearLayout也被忽略了。我认为我忽略了一些明显的事情,但如果有人对如何做到这一点有建议,将不胜感激。

4

1 回答 1

9

A drawerlayout is allowed only 2 children, the first is a main content view, the second is the drawer. You need to combine your first two views into a linear layout. http://developer.android.com/training/implementing-navigation/nav-drawer.html

于 2013-05-22T14:45:01.207 回答