【发布时间】:2020-09-08 19:47:04
【问题描述】:
我使用 Recyclerview ,您可以看到它的左对齐并且有 no margin before the first card ,并且在最后一张卡片(last card button not shown)之前没有底部边距,我该如何解决?我在卡上添加了填充,但它对我不起作用 我还在约束布局上添加了边距,但第一张卡片总是卡在顶部。
XML 代码
<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="wrap_content"
android:layout_height="wrap_content"
android:background="@color/design_default_color_surface"
app:layout_constraintHeight_max="wrap"
app:layout_constraintWidth_max="wrap">
<com.google.android.material.card.MaterialCardView
android:id="@+id/card"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Media -->
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/iconfinder_artboard_1_1790655" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title"
android:textAppearance="?attr/textAppearanceHeadline6" />
<TextView
android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="secondary_text"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.button.MaterialButton
android:id="@+id/readMore"
style="?attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Read More" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Recyclerview XML
<?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"
tools:context=".AllBooksRecycler">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="393dp"
android:layout_height="717dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
发布包含recyclerview的布局的XML。
标签: android android-constraintlayout