具体效果如下:
将这个textview 向左移动,那么都可以监听,如上图。如果控件向右移,只有第一个textview 刚刚出头的部分可以监听,如下图
貌似监听宽度还只是竖屏!?
原因:在fragment所在的 activity 布局中添加了 DrawerLayout, DrawerLayout是隐藏的,但是焦点区域覆盖了:
<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"
tools:context=".childmenu.RealTimeDataActivity">
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="51dp"/>
<include layout="@layout/app_bar" />
</RelativeLayout>
app_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:background="@color/colorBase" >
<ImageView android:id="@+id/menu_back"
android:layout_width="35dp"
android:layout_height="28dp"
android:layout_marginLeft="5dp"
android:layout_centerVertical="true"
android:src="@drawable/menu_back"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id = "@+id/titleBar"
android:text="间隔#1"
android:layout_marginLeft="45dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="14sp"/>
<ImageView android:id="@+id/menu_btn"
android:layout_marginTop="1dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:paddingRight="5dp"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:src="@drawable/menu_slide"/>
</RelativeLayout>
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="220dp"
android:layout_height="match_parent"
android:layout_gravity="right">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="right">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slide_menu"/>
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
</LinearLayout>
使用DrawerLayout一定注意焦点覆盖的问题!!!