ConstraintLayout - 底部导航与 RecyclerView 重叠
ConstrainLayout - Bottom Navigation overlaps RecyclerView
我有一个带有 AppBar 的 ConstraintLayout、2 个片段(每个片段包含一个 RecyclerView)和一个底部导航。问题是底部导航与 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,它什么都不做。
知道问题出在哪里吗?
请将滑动刷新 *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"
我有一个带有 AppBar 的 ConstraintLayout、2 个片段(每个片段包含一个 RecyclerView)和一个底部导航。问题是底部导航与 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,它什么都不做。
知道问题出在哪里吗?
请将滑动刷新 *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"