【问题标题】:In my layout there is recyclerview and bottom navigation bar but navigation bar goes behinf the recycler view在我的布局中有recyclerview和底部导航栏,但导航栏位于recycler view的后面
【发布时间】:2020-10-15 09:10:58
【问题描述】:

在我的布局中有 recyclerview 和底部导航栏,但问题是 recyclerview 占据了所有视图和底部导航栏,并且 header bad 位于 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>

【问题讨论】:

    标签: java android html android-studio android-recyclerview


    【解决方案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">
    
        <!--status bar-->
        <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" />
    
        <!--add button-->
        <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="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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 2017-04-11
      • 2021-04-02
      相关资源
      最近更新 更多