我在应用程序中实现了一个recyclreview,我所面临的问题是recycerview的第一项缺少边距底部,因此第一个元素看起来很难看,而其他所有元素都可以正常显示底部元素
这是项目的xml:
<?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:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fresco="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_15sdp"
android:layout_marginEnd="@dimen/_15sdp"
android:layout_marginTop="@dimen/_10sdp"
app:cardElevation="1dp"
android:layout_marginBottom="@dimen/_10sdp"
card_view:cardBackgroundColor="@color/white">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/book_avatar"
android:layout_width="@dimen/_80sdp"
android:layout_height="@dimen/_120sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:src="@drawable/ic_loading"
fresco:actualImageScaleType="centerCrop"
fresco:progressBarImage="@drawable/ic_loading"
fresco:progressBarAutoRotateInterval="1300"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/popular_book_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:text="@{item.title}"
android:textColor="@color/black"
android:textSize="@dimen/_14sdp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.101"
app:layout_constraintStart_toEndOf="@+id/book_avatar"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:text="@string/author_"
android:textColor="@color/black"
app:layout_constraintStart_toEndOf="@+id/book_avatar"
app:layout_constraintTop_toBottomOf="@+id/popular_book_name" />
<TextView
android:id="@+id/txt_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:text="@{item.author}"
android:textColor="@color/black"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/popular_book_name"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/txt_genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:background="@drawable/rounded_btn_grey"
android:text="@{item.genre_name}"
android:paddingStart="@dimen/_5sdp"
android:paddingEnd="5dp"
android:padding="@dimen/_3sdp"
android:textSize="@dimen/_10sdp"
android:textColor="@color/font_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.057"
app:layout_constraintStart_toEndOf="@+id/book_avatar"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<com.iarcuschin.simpleratingbar.SimpleRatingBar
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
app:layout_constraintStart_toEndOf="@+id/book_avatar"
app:layout_constraintTop_toBottomOf="@+id/txt_genre"
app:srb_borderColor="@color/yellow"
app:srb_fillColor="@color/yellow"
app:srb_isIndicator="true"
app:srb_numberOfStars="5"
app:srb_rating="1"
app:srb_starCornerRadius="5"
app:srb_starSize="@dimen/_15sdp"
app:srb_stepSize="0.5" />
<Button
android:id="@+id/read_btn"
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_25sdp"
android:layout_marginStart="8dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp"
android:background="@drawable/rounded_btn"
android:elevation="100dp"
android:shadowColor="@color/colorPrimary"
android:text="@string/view_details"
android:textAllCaps="false"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.08"
app:layout_constraintStart_toEndOf="@+id/book_avatar"
app:layout_constraintTop_toBottomOf="@+id/rating" />
<TextView
android:id="@+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:text="@{item.average_rating}"
app:layout_constraintStart_toEndOf="@+id/rating"
app:layout_constraintTop_toBottomOf="@+id/txt_genre" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>