#java #android #android-recyclerview
Вопрос:
Итак, у меня есть горизонтальный вид переработчика, и я помещаю в него изображения, но они слишком далеки друг от друга, как я мог бы это исправить?
Код макета, в котором у меня есть мое изображение
<?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>
Комментарии:
1. Попробуйте использовать wrap_content в RecyclerView
2. попробуйте удалить
android:layout_marginStart="19dp"
иandroid:layout_marginLeft="19dp"
изImageView
3. Нет, ничего из этого не сработало
Ответ №1:
измените свой ConstraintLayout android:layout_width=»match_parent» на
android:layout_width=»wrap_content»
измените свой android для просмотра вторсырья:layout_width=»416dp» на
android:layout_width=»совпадение»