[英]How to make view on top of another view in CoordinatorLayout?
这是我的看法。 我希望mainContainer
中的所有视图都位于屏幕顶部。 如果来自secondContainer
的视图位于相同的 position,则它们需要被来自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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.