android - TabLayout 和 viewPager 重叠
问题描述
我有一个 tabLayout 和 viewPager2 用于显示片段。片段中有recyclerview。它工作得很好,但 recyclerview 重叠了一些布局项目。我试图在个人资料照片下显示 viewpager,但 constraintLayout 变为全宽和全高,然后我无法正确显示 recyclerview。
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.ProfileFragment">
<androidx.appcompat.widget.Toolbar
android:id="@+id/myToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:elevation="8dp"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="@string/profile" />
<androidx.cardview.widget.CardView
android:id="@+id/coverPhoto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="24dp"
app:layout_anchor="@id/myToolbar"
app:layout_anchorGravity="bottom">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/ic_launcher_background" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/profile_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="29dp"
app:layout_anchor="@id/coverPhoto"
app:layout_anchorGravity="bottom|center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/ic_baseline_person" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/iconChange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/light_orange"
app:cardCornerRadius="16dp"
app:layout_anchor="@id/profile_photo"
app:layout_anchorGravity="top|end">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dp"
android:src="@drawable/ic_round_camera"
app:tint="@color/white" />
</androidx.cardview.widget.CardView>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_anchor="@id/profile_photo"
app:layout_anchorGravity="bottom">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/viewPager" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
片段布局:
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.PersonalProductFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/personalProductsRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:fadingEdge="horizontal"
android:fadingEdgeLength="25dp"
android:requiresFadingEdge="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
解决方案
推荐阅读
- open-policy-agent - 根据 OPA 策略过滤数据集
- bash - Bash `install -d` 用于具有相同名称的现有文件
- django - 如何在基于函数的 api_view 中指定 DRF oauth required_scopes?
- mysql - 查询不正确地设置用户的排名,取决于他的总分
- excel - Excel:重复项之间的小时数差异
- kotlin - Kotlin 空安全和布尔表达式
- python - RTU Modbus 的 Python 脚本
- splunk - Splunk - 查找值 + 静态搜索字符串 = 输出计数
- angular - 如何在 Ionic 应用程序的服务内向方法添加错误验证?
- c++ - 如何将 utf-8 中的字符串发送到 irc 服务器?