您可以使用 setOnTouchListener 方法来检测顶部视图上的触摸事件并将其传播到下面的视图。
topButton = findViewById(R.id.topButton);
underneathButton = findViewById(R.id.underneathButton);
topButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Propagate touch events to the view underneath
underneathButton.dispatchTouchEvent(event);
return true;
}
});
underneathButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle click on the view underneath
// Add your logic here
}
});
更改在父视图中添加视图的顺序。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="@id/toolbar_feed"
layout="@layout/toolbar_feed"/>
<include
android:id="@+id/navigation_bottom_layout"
layout="@layout/bottom_navigation_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>