android - 在 Coordinator Layout 中排列 View

标签 android view coordinator-layout

我在将框架布局置于底部抽屉导航下方时遇到问题(是的,我将其放在顶部 :))。现在 Frame 布局的顶部被 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>

关于android - 在 Coordinator Layout 中排列 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50950502/

相关文章:

java - Android - 电影卡住时的动画 gif,仅显示图像的一小部分

android - 带有 TabLayout 的无限 ViewPager

android - 在 Android 中滚动时折叠布局

java - Android应用程序计算错误和崩溃

android - 如何在 Android 应用程序中永久禁用 NDEF 标签发现而不仅仅是 Activity?

mysql - 创建一个 View ,其中值显示为变量

安卓.view.InflateException : Binary XML file line #33: Error inflating class

android - 自定义可扩展 ListView 添加按钮

java - 在android中的textview上创建一条水平线