如何在片段中实现触摸事件功能?

问题描述

我正在使用一个片段来显示recyclerview。我的目标是拥有多点触摸功能,以便可以捏捏手势

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 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=".scoreboardFragment"
    android:focusable="true"
    android:clickable="true">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/scoreboardView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:clickable="true"
        />
</androidx.constraintlayout.widget.ConstraintLayout>

在我的片段类中,我有功能

 @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
        View rootView =  inflater.inflate(R.layout.fragment_scoreboard,container,false);
        rootView.setonTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v,MotionEvent event){
                System.out.println("TEST");
                return true;

            }
        });

从来没有反应。我还将itemtouchhelper与simplecallbacks一起使用,以在回收器视图中注册对项目的单击,效果很好,如果有大量项目,也可以在列表中滚动。因此,这里有一些触摸功能。当我在主要活动中使用onTouchListener时,它工作正常,但将其移至片段时却无法正常工作。

我不确定是否还有其他相关信息,我们将不胜感激。

解决方法

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

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...