2013-07-13 37 views
0

试图在hereAndroid的抽屉布局与主要活动

提到尝试了这一点之后,抽屉布局的例子,我增加了一些元素,比如一个按钮,以主要布局。这是我做的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:onClick="openTestButtonActivity" 
     android:text="@string/testing" /> 

    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
      . 
      . 
      . 
    </android.support.v4.widget.DrawerLayout> 

</RelativeLayout> 

现在,抽屉工作正常,但我无法激活我的按钮。布局的顺序有什么问题,我做错了吗?

回答

1

是的,布局顺序是错误的。在relativeLayout视图中按照代码添加的顺序排列。所以如果你先添加按钮然后添加drawerLayout,drawerLayout覆盖按钮。所以你应该先添加DrawerLayout,然后添加Button。