【问题标题】:ConstrainLayout - Bottom Navigation overlaps RecyclerViewConstraintLayout - 底部导航重叠 RecyclerView
【发布时间】:2020-05-28 08:53:36
【问题描述】:

我有一个带 AppBar、2 个片段(每个片段包含一个 RecyclerView)和一个底部导航的 ConstraintLayout。问题是底部导航与 RecyclerView 最后一行重叠。

这是我的布局

<?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"
    android:background="@color/template_grey_dark"
    tools:context=".presentation.ui.activity.MainActivity">

    <include
        android:id="@+id/AppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        layout="@layout/app_bar" />

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/SwipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        *app:layout_constraintTop_toBottomOf="@+id/AppBar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">
        <androidx.core.widget.NestedScrollView
            android:id="@+id/NestedScrollView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="true"
            android:fillViewport="true"
            android:fitsSystemWindows="true"
            android:padding="@dimen/activity_horizontal_margin_8">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <androidx.fragment.app.FragmentContainerView
                    android:id="@+id/FragmentMovie"
                    android:name=".presentation.ui.fragment.MovieFragment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    tools:layout="@layout/fragment_movie"
                    android:layout_marginTop="@dimen/activity_horizontal_margin_16"/>
                <androidx.fragment.app.FragmentContainerView
                    android:id="@+id/FragmentTVShow"
                    android:name=".presentation.ui.fragment.TVShowFragment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    tools:layout="@layout/fragment_tv_show"
                    android:layout_marginTop="@dimen/activity_horizontal_margin_16"/>
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    <LinearLayout
        android:id="@+id/FabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toTopOf="@+id/BottomNavigationLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:gravity="end">
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|bottom"
            android:src="@mipmap/baseline_filter_list_white"
            android:contentDescription="I'm Feeling Lucky"
            android:layout_margin="@dimen/activity_vertical_margin_16"
            app:backgroundTint="@color/black"
            app:tint="@color/white"/>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/BottomNavigationLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">
        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/BottomNavigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:menu="@menu/bottom_navigation"
            android:background="@color/black"
            style="bottomNavigationStyle"/>
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

如果我添加

app:layout_constraintBottom_toTopOf="@+id/BottomNavigationLayout"

对于 SwipeRefreshLayout,它什么也不做。

知道问题可能是什么吗?

【问题讨论】:

    标签: android android-layout android-recyclerview android-constraintlayout


    【解决方案1】:

    请将您的滑动刷新*app:layout_constraintTop_toBottomOf="@+id/AppBar" 编辑为app:layout_constraintTop_toBottomOf="@id/AppBar",将您的app:layout_constraintBottom_toTopOf="@id/+BottomNavigationLayout" 编辑为app:layout_constraintBottom_toTopOf="@id/BottomNavigationLayout",最后,将 SwipeRefreshLayout 的高度设置为 0dp 以使其 match_constraint 使用, android:layout_height="0dp"

    【讨论】:

    • 很高兴它有帮助! ?
    猜你喜欢
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多