无法在画布上绘画和聆听触摸以同时查看

我的主要活动包含一个=Join(Parameters!Keys.Value,",") 。如果触摸,它将运行动画。 在同一屏幕上,我可以绘制带有扩展视图的线(示例)。

来自画布的

textView必须返回true,但是来自textView的OnTouchEvent将永远不会得到它。

我希望两者都可以使用触摸屏。我该怎么办?

Mainactivity.java

onTouch

activity_main.XML

public class Mainactivity extends AppCompatactivity {
    TextView tv,lettres;
    TranslateAnimation animation;
    ConstraintLayout constraintLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = findViewById(R.id.tv);
        tv.setX(100);
        tv.setY(100);
        constraintLayout = findViewById(R.id.cl);
        lettres = new TextView(this);
        constraintLayout.addView(lettres);
        lettres.setVisibility(View.GONE);
        lettres.setText("test");
        tv.setOnTouchListener(touchListener);
    }

    private View.OnTouchListener touchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view,MotionEvent motionEvent) {
            if (view == tv){

                        lettres.setX(50);
                        lettres.setY(50);
                        animation = new TranslateAnimation(0,10,10);
                        lettres[i].startAnimation(animation[i]);
           }
            return false;
        }
    };
}

DrawingView.java

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/cl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Mainactivity">
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
    <fr.DrawingView
        android:id="@+id/myDrawingView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
cuihe 回答:无法在画布上绘画和聆听触摸以同时查看

因为您的主布局占用了touch事件。 然后在onTouchEvent内部返回true

本文链接:https://www.f2er.com/3155902.html

大家都在问