如何解决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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。