Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

android - Drawerlayout children views overlapping

I've been trying to make a DrawerLayout that has a ViewPager and a LinearLayout attached to the bottom of the DrawerLayout. The problem is that the ViewPager and LinearLayout are overlapping at the top of the view, and all my efforts to move the LinearLayout down have failed so far.

The XML Layout:

<?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>

I've tried adding several things to linear_layout:

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

But all of these values seem to be ignored, even changing android:layout_width of the LinearLayout is ignored. I think i'm overlooking something obvious but if anyone has suggestions on how to do this it would be greatly appreciated.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...