如何在特定子视图上调用 onTouchListener

问题描述

我有一个简单的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".pkgActivity.FragmentDotsNoViewPager">

<!-- Todo: Update blank fragment layout -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical">

    <com.mazenrashed.dotsindicator.DotsIndicator
        android:id="@+id/omgg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:longClickable="false"
        app:unselected_dot_resource="@drawable/circle_gray">

    </com.mazenrashed.dotsindicator.DotsIndicator>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#BD5050"
        android:text="TextView" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

</FrameLayout>

我的代码

dotsIndicator = (DotsIndicator) view.findViewById(R.id.omgg);
dotsIndicator.getRootView().setonTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v,MotionEvent event) {
       Toast.makeText(getActivity(),"my view is called",Toast.LENGTH_LONG).show();
         return false;
       }
});

//if i call this method instead of the method above i never enter the method
dotsIndicator.setonTouchListener(new View.OnTouchListener() {
   @Override
   public boolean onTouch(View v,MotionEvent event) {
      Toast.makeText(getActivity(),"i never get called :(",Toast.LENGTH_LONG).show();
        return false;
      }
});

问题是我使用了 DotsIndicator 库,当我选择一个点时,它会自动更改点。但我不希望那样,所以我尝试覆盖 setonTouchListener,除非我使用 DotsIndicator 视图,否则它永远不会被调用。但是当我使用 View 时,当我还选择 TextView 或 Button 但我不想要那个时,该函数会被调用。我只想防止触摸一个点。我错过了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)