使用毕加索在imageView上使用java包装内容
我有一个社交媒体,我想把帖子上图像的高度添加到wrap_content
,但是当我检索Firebase的图像并将其显示在recycler view
上时,图像不会显示在wrap_content
上。我还用毕加索来设置图像
我用来设置图像(与毕加索一起)的代码部分:
Picasso.get()
.load(postList.get(position).getImgUrl())
.placeholder(R.drawable.m1)
.fit()
.centerCrop()
.into(holder.postImg);
发布项目。xml:
<?xml version="1.0" encoding="utf-8"?>
<安卓x.cardview.widget.CardView xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:layout_margin="8dp"
app:cardCornerRadius="6dp"
app:cardElevation="10dp"
安卓:layout_marginBottom="30dp">
<安卓x.constraintlayout.widget.ConstraintLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content">
<TextView
安卓:id="@+id/post_username"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_gravity="start"
安卓:layout_marginStart="3dp"
安卓:layout_marginTop="8dp"
安卓:layout_marginBottom="8dp"
安卓:text="george the developer"
安卓:textSize="17sp"
安卓:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/post_image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.038"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<ImageView
安卓:id="@+id/post_image"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_contenta\"
安卓:src="@drawable/m1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/post_username" />
<ImageButton
安卓:id="@+id/likeBtn"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginEnd="15dp"
安卓:background="@null"
app:layout_constraintBottom_toTopOf="@+id/post_image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/post_username"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/like_emoji_before" />
<TextView
安卓:id="@+id/like_counter"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginEnd="5dp"
安卓:text="0"
安卓:textSize="17sp"
安卓:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/post_image"
app:layout_constraintEnd_toStartOf="@+id/likeBtn"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/post_username"
app:layout_constraintTop_toTopOf="parent" />
</安卓x.constraintlayout.widget.ConstraintLayout>
</安卓x.cardview.widget.CardView>
# 1 楼答案
您需要删除
centerCrop()
以避免裁剪图像,同时删除fit()
以尝试计算适当的图像大小,尽管您需要其完整大小现在我们有:
对于
ImageView
:添加以下两个属性以确保图像具有完整大小