我的主要活动包含一个=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,0,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>
答案 0 :(得分:1)
因为您的主布局占用了touch事件。 然后在onTouchEvent内部返回true