在我的布局中有一个RecyclerView和底部导航栏,但导航栏在RecyclerView的后面。

huangapple go评论61阅读模式
英文:

In my layout there is recyclerview and bottom navigation bar but navigation bar goes behinf the recycler view

问题

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/baseLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <!--status bar-->
    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/default_activity_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:backgroundTint="@color/buttoncolor"
        app:menu="@menu/default_menu" />

    <!--add button-->
    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:backgroundTint="@color/buttoncolor"
        app:fabAlignmentMode="end"
        app:fabCradleMargin="6.2sp"
        app:fabCradleRoundedCornerRadius="15sp"
        app:menu="@menu/app_bar_menu" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:backgroundTint="#ED4444"
        android:onClick="openCamera"
        android:src="@drawable/ic_add"
        app:layout_anchor="@id/bottomAppBar"
        app:maxImageSize="35sp"
        app:tint="@color/white" />

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

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rw"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/empty_list" />

        <LinearLayout
            android:id="@+id/empty_list"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/empty_list_icon"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/ic_no_data" />

            <TextView
                android:id="@+id/empty_list_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:text="Scan the files"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:textSize="24dp"
                android:gravity="center_horizontal" />

            <TextView
                android:id="@+id/empty_list_message"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Scan to make something great"
                android:paddingLeft="40dp"
                android:paddingRight="40dp"
                android:gravity="center_horizontal" />

        </LinearLayout>

    </RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
英文:

In my layout there is recyclerview and bottom navigation bar but the problem is that the recyclerview occupies all the view and the bottom navigation bar and the header bad goes behind the recycler view. I've sucessfully implemented the material dependency.

this is the layout:

在我的布局中有一个RecyclerView和底部导航栏,但导航栏在RecyclerView的后面。

This is the code of the layout.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:id=&quot;@+id/baseLayout&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:orientation=&quot;vertical&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;!--status bar--&gt;
&lt;com.google.android.material.bottomappbar.BottomAppBar
android:id=&quot;@+id/default_activity_button&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_gravity=&quot;top&quot;
android:backgroundTint=&quot;@color/buttoncolor&quot;
app:menu=&quot;@menu/default_menu&quot; /&gt;
&lt;!--add button--&gt;
&lt;com.google.android.material.bottomappbar.BottomAppBar
android:id=&quot;@+id/bottomAppBar&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_gravity=&quot;bottom&quot;
android:backgroundTint=&quot;@color/buttoncolor&quot;
app:fabAlignmentMode=&quot;end&quot;
app:fabCradleMargin=&quot;6.2sp&quot;
app:fabCradleRoundedCornerRadius=&quot;15sp&quot;
app:menu=&quot;@menu/app_bar_menu&quot; /&gt;
&lt;com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;match_parent&quot;
android:backgroundTint=&quot;#ED4444&quot;
android:onClick=&quot;openCamera&quot;
android:src=&quot;@drawable/ic_add&quot;
app:layout_anchor=&quot;@id/bottomAppBar&quot;
app:maxImageSize=&quot;35sp&quot;
app:tint=&quot;@color/white&quot; /&gt;
&lt;RelativeLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;androidx.recyclerview.widget.RecyclerView
android:id=&quot;@+id/rw&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:layout_below=&quot;@+id/empty_list&quot; /&gt;
&lt;LinearLayout
android:id=&quot;@+id/empty_list&quot;
android:visibility=&quot;gone&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:gravity=&quot;center_vertical|center_horizontal&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;ImageView
android:id=&quot;@+id/empty_list_icon&quot;
android:layout_width=&quot;200dp&quot;
android:layout_height=&quot;200dp&quot;
android:background=&quot;@drawable/ic_no_data&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/empty_list_title&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:textStyle=&quot;bold&quot;
android:text=&quot;Scan the files&quot;
android:paddingLeft=&quot;20dp&quot;
android:paddingRight=&quot;20dp&quot;
android:textSize=&quot;24dp&quot;
android:gravity=&quot;center_horizontal&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/empty_list_message&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Scan to make something great&quot;
android:paddingLeft=&quot;40dp&quot;
android:paddingRight=&quot;40dp&quot;
android:gravity=&quot;center_horizontal&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;/RelativeLayout&gt;
&lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;

<!-- end snippet -->

答案1

得分: 1

请尝试通过为BottomAppBar指定特定的高度,然后为RelativeLayout提供上下边距:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/baseLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <!--状态栏-->
    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/default_activity_button"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="top"
        android:backgroundTint="@color/buttoncolor"
        app:menu="@menu/default_menu" />

    <!--添加按钮-->
    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="bottom"
        android:backgroundTint="@color/buttoncolor"
        app:fabAlignmentMode="end"
        app:fabCradleMargin="6.2sp"
        app:fabCradleRoundedCornerRadius="15sp"
        app:menu="@menu/app_bar_menu" />


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:backgroundTint="#ED4444"
        android:onClick="openCamera"
        android:src="@drawable/ic_add"
        app:layout_anchor="@id/bottomAppBar"

        app:maxImageSize="35sp"
        app:tint="@color/white" />


    <RelativeLayout
        android:layout_marginTop="50dp"
        android:layout_marginBottom="50dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rw"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/empty_list" />

        <LinearLayout
            android:id="@+id/empty_list"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/empty_list_icon"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:background="@drawable/ic_no_data" />

            <TextView
                android:id="@+id/empty_list_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:text="扫描文件"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:textSize="24dp"
                android:gravity="center_horizontal"/>

            <TextView
                android:id="@+id/empty_list_message"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="扫描以创造美好"
                android:paddingLeft="40dp"
                android:paddingRight="40dp"
                android:gravity="center_horizontal" />

        </LinearLayout>


    </RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
英文:

Try this by giving specific height to the BottomAppBar. Then provide margin top and Bottom to the RelativeLayout :

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:id=&quot;@+id/baseLayout&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:orientation=&quot;vertical&quot;
tools:context=&quot;.MainActivity&quot;&gt;
&lt;!--status bar--&gt;
&lt;com.google.android.material.bottomappbar.BottomAppBar
android:id=&quot;@+id/default_activity_button&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;50dp&quot;
android:layout_gravity=&quot;top&quot;
android:backgroundTint=&quot;@color/buttoncolor&quot;
app:menu=&quot;@menu/default_menu&quot; /&gt;
&lt;!--add button--&gt;
&lt;com.google.android.material.bottomappbar.BottomAppBar
android:id=&quot;@+id/bottomAppBar&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;50dp&quot;
android:layout_gravity=&quot;bottom&quot;
android:backgroundTint=&quot;@color/buttoncolor&quot;
app:fabAlignmentMode=&quot;end&quot;
app:fabCradleMargin=&quot;6.2sp&quot;
app:fabCradleRoundedCornerRadius=&quot;15sp&quot;
app:menu=&quot;@menu/app_bar_menu&quot; /&gt;
&lt;com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;match_parent&quot;
android:backgroundTint=&quot;#ED4444&quot;
android:onClick=&quot;openCamera&quot;
android:src=&quot;@drawable/ic_add&quot;
app:layout_anchor=&quot;@id/bottomAppBar&quot;
app:maxImageSize=&quot;35sp&quot;
app:tint=&quot;@color/white&quot; /&gt;
&lt;RelativeLayout
android:layout_marginTop=&quot;50dp&quot;
android:layout_marginBottom=&quot;50dp&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;androidx.recyclerview.widget.RecyclerView
android:id=&quot;@+id/rw&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:layout_below=&quot;@+id/empty_list&quot; /&gt;
&lt;LinearLayout
android:id=&quot;@+id/empty_list&quot;
android:visibility=&quot;gone&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:gravity=&quot;center_vertical|center_horizontal&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;ImageView
android:id=&quot;@+id/empty_list_icon&quot;
android:layout_width=&quot;200dp&quot;
android:layout_height=&quot;200dp&quot;
android:background=&quot;@drawable/ic_no_data&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/empty_list_title&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:textStyle=&quot;bold&quot;
android:text=&quot;Scan the files&quot;
android:paddingLeft=&quot;20dp&quot;
android:paddingRight=&quot;20dp&quot;
android:textSize=&quot;24dp&quot;
android:gravity=&quot;center_horizontal&quot;/&gt;
&lt;TextView
android:id=&quot;@+id/empty_list_message&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Scan to make something great&quot;
android:paddingLeft=&quot;40dp&quot;
android:paddingRight=&quot;40dp&quot;
android:gravity=&quot;center_horizontal&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;/RelativeLayout&gt;
&lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;

huangapple
  • 本文由 发表于 2020年10月15日 17:10:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/64368329.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定