如何使视图在CoordinatorLayout的另一个视图的顶部?



这是我的观点。我希望mainContainer中的所有视图都在屏幕顶部。如果来自secondContainer的视图位于相同位置,则需要由mainContainer的视图覆盖。

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/mainContainer"
layout="@layout/view_home_content"
app:layout_anchorGravity="bottom"/>
<include
android:id="@+id/secondContainer"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

现在secondContainer的所有内容都出现在mainContainer的视图之上

哦,解决方法很简单。我只是改变了视图的顺序

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/secondContainer"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"/>
<include
android:id="@+id/mainContainer"
layout="@layout/view_home_content"
app:layout_anchorGravity="bottom"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

最新更新