【发布时间】:2021-02-11 08:23:23
【问题描述】:
我想制作一个recyclerview 来显示用户拍摄的一些图像。在每个项目的回收站视图中,我在左侧都有作者和日期,在center-right 中,我调整了图像的大小,例如使用200dp 宽度和100dp 高度,当用户点击它时,我会显示它是全尺寸的。
问题是我无法在recyclerview中设置图像项的width和height。我尝试了所有的scaleType,但没有任何效果,图像大小调整不正确或太高或太低。
recyclerview的xml:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/photoList"
android:layout_width="350dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/MarginStart20"
android:layout_marginTop="15dp"
android:background="@drawable/reclycler_border"
android:paddingStart="10dp"
android:paddingEnd="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintHeight_default="wrap"
app:layout_constraintHeight_max="300dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView20"
tools:listitem="@layout/photo_list_item" />
每个项目的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="wrap_content"
android:paddingBottom="10dp">
<TextView
android:id="@+id/photoAuthorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Mario Rossi" />
<TextView
android:id="@+id/photoDateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:singleLine="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/photoAuthorView"
tools:text="10/01/2021\n10:00:00" />
<ImageView
android:id="@+id/photoView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginStart="60dp"
android:scaleType="fitEnd"
app:layout_constraintStart_toEndOf="@+id/photoAuthorView"
app:layout_constraintStart_toEndOf="@+id/photoAuthorView"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
</androidx.constraintlayout.widget.ConstraintLayout>
this是现在的样子,你可以看到图片位置不好,我要在作者和日期的右边
【问题讨论】:
-
我添加了现在的截图
-
@ʍѳђઽ૯ท 如果您看到图片大小调整不正确
-
删除此应用:layout_constraintBottom_toBottomOf="@+id/photoDateView" 并添加到应用:layout_constraintTop_toTopOf="@id/photoAuthorView" 图像视图底部与日期视图底部对齐
-
@KishanMaurya 我做到了,但是现在如何解决对齐问题?我想要它在作者和日期的右边...请看我添加的新图片
-
android:scaleType="fitEnd" 尝试使用 fitCenter 或 fitxy
标签: android xml kotlin android-recyclerview