ConstraintLayoutとScrollViewを使ってAndroidのBottomNavigationBar

Zatosasa:

私は常に見える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>
droidbaza:

代わりにアンドロイド:paddingBottomの= "のattr / actionBarSize?":layout_marginBottom = "64DP" だけでアンドロイドを追加

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=389772&siteId=1