繁体   English   中英

如何在 CoordinatorLayout 中使视图位于另一个视图之上?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM