繁体   English   中英

浮动操作按钮块底部导航栏

[英]floating action button blocks bottom navigation bar

我希望我的浮动操作按钮位于列表视图上方和导航栏上方,但我似乎无法使其工作。 (包含布局是导航栏)。

这就是它现在的样子

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".SessionsList">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView

            android:id="@+id/lvSessions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:src="@drawable/ic_baseline_add_24"
            android:contentDescription=""
            android:layout_margin="16dp" />

        <include layout="@layout/activity_base"/>

    </FrameLayout>


</LinearLayout>

这是导航栏布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".BaseActivity">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:itemBackground="@color/orange"
        app:itemIconTint="@drawable/selector"
        app:itemTextColor="@drawable/selector"
        android:layout_gravity="bottom"
        app:menu="@menu/menu_navigation" />

</LinearLayout>

我试着把它放在一个框架布局中并四处移动,但我无法让它像我想要的那样工作。

像这样更改您的主要布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <ListView
            android:id="@+id/lvSessions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


        <include
            android:id="@+id/baseLayout"
            layout="@layout/activity_base"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_above="@+id/baseLayout"
            android:layout_alignParentEnd="true"
            android:src="@drawable/g1" />

    </RelativeLayout>


</FrameLayout>

并且还像这样更改 activity_base 布局

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

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="60dp"
       android:layout_gravity="bottom"
        app:itemBackground="@color/black" />

</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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