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

来源:互联网 发布:内蒙广电网络登录入口 编辑:程序博客网 时间:2024/05/18 20:06

问题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>

谢谢阅读。你们的支持是我坚持的下去的动力。

原创: Vampire hunter

原创粉丝点击