zoukankan      html  css  js  c++  java
  • 假期学习记录11(NavigationView点击事件无效)

    今天开发碰到一个很恶心的问题,以前能用的NavigationView突然点击事件就没响应了,也算是NavigationView的一个坑吧,特此记录一下。

    在我们写滑动布局时会建立一个item然后在主布局中使用NavigationView来调用Item的xml布局,代码如下,我的Item布局名字叫nav_header_main

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start"
        android:background="@drawable/mainbackground">
       <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <ImageView
                    android:src="@drawable/main_run"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
                <TextView
                    android:text="运动"
                    android:textStyle="bold"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="12dp"
                    android:textSize="15dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
    </android.support.v4.widget.DrawerLayout>

    此时NavigationView点击事件是没有问题的,但是切记不要再NavigationView下面再写布局了,也就是说NavigationView要位于整个布局的最下方,否则NavigationView的点击事件会被下面的布局挡住,就会导致NavigationView中的Item的点击事件无效

  • 相关阅读:
    [清华集训2016]温暖会指引我们前行——LCT+最大生成树
    BZOJ1415[Noi2005]聪聪和可可——记忆化搜索+期望dp
    NOIP2018游记
    BZOJ4832[Lydsy1704月赛]抵制克苏恩——期望DP
    BZOJ1906树上的蚂蚁&BZOJ3700发展城市——RMQ求LCA+树链的交
    BZOJ2822[AHOI2012]树屋阶梯——卡特兰数+高精度
    BZOJ4001[TJOI2015]概率论——卡特兰数
    BZOJ1805[Ioi2007]Sail船帆——线段树+贪心
    [IOI2018]排座位——线段树
    BZOJ3718[PA2014]Parking——树状数组
  • 原文地址:https://www.cnblogs.com/837634902why/p/12301282.html
Copyright © 2011-2022 走看看