android DrawerLayout 点击穿透、点击自身消失等问题解决

问题1:在DrawerLayout内部中点击,DrawerLayout的布局莫名消失。

解决1:DrawerLayout的布局必须放在页面主布局的下面。

To use a DrawerLayout, position your primary content view as the first child with a width and height of match_parent. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.

问题2:点击DrawerLayout的布局,会触发被滑出页面挡住的布局中的点击事件。

解决2:在DrawerLayout的最外层布局中,设置android:clickable="true"

问题3: java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.

解决3:设置DrawerLayout的height为 match_parent.
Drawers commonly use match_parent for height with a fixed width.

下面贴上一段代码供大家参考:

<android.support.v4.widget.DrawerLayout
    android:id="@+id/side_menu"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/widget_main">

    <!--main layout-->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         >
         ............
         主布局代码 
         ............
         ............
    </RelativeLayout>

    <!-- side menu -->
    <RelativeLayout
        android:id="@+id/side_menu_content"
        android:layout_width="match_parent"
        android:clickable="true"
        android:layout_height="match_parent"
        android:layout_gravity="left">

        <RelativeLayout
            android:id="@+id/rl_side_menu_quit"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:background="@color/title_bg"
            android:gravity="bottom">

            <ImageView
                android:id="@+id/img_quit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:padding="5dp"
                android:src="@drawable/quit" />

            <TextView
                android:id="@+id/tv_quit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_toRightOf="@id/img_quit"
                android:gravity="center_vertical"
                android:text="退出"
                android:textColor="@color/white"
                android:textSize="18sp" />
        </RelativeLayout>
        
    </RelativeLayout>


</android.support.v4.widget.DrawerLayout>
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Code王工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值