【问题标题】:I Have a horizontal recyclerview with images in it but they are way too far from each other我有一个带有图像的水平回收视图,但它们彼此相距太远
【发布时间】:2021-10-07 15:17:50
【问题描述】:

好的,我有一个水平回收器视图,我正在将图像放入其中,但它们彼此相距太远,我该如何解决?

我有图片的布局代码

<?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="wrap_content">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="106dp"
        android:layout_height="171dp"
        android:layout_marginStart="19dp"
        android:layout_marginLeft="19dp"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:srcCompat="@tools:sample/avatars" />

</androidx.constraintlayout.widget.ConstraintLayout>

我有回收站视图的布局代码

<?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=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="416dp"
        android:layout_height="174dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • 尝试在recyclerView中使用wrap_content
  • 尝试从ImageView中删除android:layout_marginStart="19dp"android:layout_marginLeft="19dp"
  • 不,这些都不起作用

标签: java android android-recyclerview


【解决方案1】:

将您的约束布局 android:layout_width="match_parent" 更改为

android:layout_width="wrap_content"

将你的 recyclerView android:layout_width="416dp" 更改为

android:layout_width="match_parent"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    相关资源
    最近更新 更多