代码如下
public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
findViewById(R.id.button).setOnClickListener(v -> {
Utils.showToast("Btn Coming.");
});
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
findViewById(R.id.container).dispatchTouchEvent(ev);
return false;
}
}
xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginEnd="129dp"
android:layout_marginBottom="36dp"
android:text="normal button"
android:layout_centerHorizontal="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</RelativeLayout>
问题:当点击button时,事件传递的流向?会不会回调OnClickListener()?为什么?