如何解决如何在特定子视图上调用 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 举报,一经查实,本站将立刻删除。