java - Android BottomNavigationBar 使用 ConstraintLayout 和 ScrollView

标签 java android android-layout android-fragments

我正在创建一个简单的应用程序,用于水平显示音乐和播客列表,在屏幕底部我希望始终可见 BottomNavigationBar。但是如果没有在 ScrollView 上添加显式边距,我的 podcast_list 的文本就会被隐藏,感觉就像黑客攻击,是否有更好更干净的方法来实现相同的结果?

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="64dp"> <---- HACK ?

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:context=".MainActivity">

            <TextView
                android:id="@+id/podcast_category"
                style="@style/categories"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/podcasts_category_text"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@id/parent" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/podcast_list"
                style="@style/media_list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@id/podcast_category" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>

最佳答案

相反 android:layout_marginBottom="64dp"只需添加 android:paddingBottom="?attr/actionBarSize"

关于java - Android BottomNavigationBar 使用 ConstraintLayout 和 ScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60990791/

相关文章:

android - 当我的应用程序未运行时,如何启动 iBeacon?

java - 从 PHP 检测 android java 客户端连接超时

java - 错误ArrayIndexOutOfBoundsException仅有时发生,用户权限?

安卓 : Application does not seek into layout-land when the device changes his orientation

android - 在 xml 之外应用布局属性有什么缺点?

java - 如何控制 Java 类中字段的可见性?

java - xpath text() 比较

Android - Horizo​​ntalListView 没有在类文件的 XML 中膨胀

java - 为什么具有区域偏移量的 LocalDateTime 格式?

java - 如何通过 TCP 连接发送字节数组(java 编程)