簡體   English   中英

在協調器布局中排列視圖

[英]Arrange views in Coordinator Layout

我在將“框架”布局設置在“底部導航抽屜”下方時遇到問題(是的,我將其放在頂部:)。 現在,BND隱藏了幀布局的頂部,因為它與BND一樣與父頂部對齊,而不是與BND底部對齊。

這是代碼:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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"
    android:id="@+id/coordID">

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/BND_ID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/m_navigation"
        />

    <FrameLayout
        android:id="@+id/fID2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/dummyFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="16dp"
        app:srcCompat="@drawable/ic_settings"
        app:layout_insetEdge="bottom" />

  </android.support.design.widget.CoordinatorLayout>

您應該嘗試將它們包裝在RelativeLayout ,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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"
    android:id="@+id/coordID">

    <RelativeLayout
        android:id="@+id/relativeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <android.support.design.widget.BottomNavigationView
            android:id="@+id/BND_ID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            app:menu="@menu/m_navigation" />

        <FrameLayout
            android:id="@+id/fID2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/BND_ID"/>

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/dummyFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_gravity="end|bottom"
        app:layout_anchor="@+id/relativeLayout"
        app:layout_anchorGravity="right|bottom"
        app:layout_insetEdge="bottom"
        app:srcCompat="@drawable/ic_settings" />



</android.support.design.widget.CoordinatorLayout>

CoordinatorLayout只是docs中所述的超強FrameLayout。

這就是視圖重疊的原因。 除非您要使用此視圖組提供的任何行為,否則建議您更改為其他布局設置,例如

 <RelativeLayout
    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">

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/BND_ID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/m_navigation" />

    <FrameLayout
        android:id="@+id/fID2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/BND_ID">
    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/dummyFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_gravity="end|bottom"
        app:layout_insetEdge="bottom"
        app:srcCompat="@drawable/ic_settings" />


</RelativeLayout>

或利用其中的coordinatorLayout行為之一

例如。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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"
   android:id="@+id/coordID">

<android.support.design.widget.BottomNavigationView
    android:id="@+id/BND_ID"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/windowBackground"
    //Add the line below
    app:layout_scrollFlags="scroll|enterAlways"
    app:menu="@menu/m_navigation"/>

<FrameLayout
    android:id="@+id/fID2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    //Add the line below
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/dummyFAB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:layout_margin="16dp"
    app:srcCompat="@drawable/ic_settings"
    app:layout_insetEdge="bottom" />

</android.support.design.widget.CoordinatorLayout>

因此,當您將任何內容放入frameLayout滾動條時,您的底部導航都將隱藏。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM