使用 Glide 检索时图像变得模糊
Image gets blurry while retrieving with Glide
所以我正在开发这个聊天应用程序。我可以发送短信和图片。
问题是每当我发送或接收图像时图像变得模糊。虽然当我刷新布局时(我有 SwipeRefreshLayout)图像变得清晰。
我有典型的适配器 class、recyclerView 和图像布局。
这仅发生在 Glide 图片库中,并且与 Picasso 配合得很好。但我只想使用 Glide。这可能是什么问题?
以下是我使用 Glide 的方式:
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
switch (holder.getItemViewType()){
case 1:
ViewHolder1 viewHolder1 = (ViewHolder1)holder;
viewHolder1.Text.setText(messageList.get(position).getMessage());
break;
case 2:
ViewHolder2 viewHolder2 = (ViewHolder2)holder;
Glide.with(viewHolder2.Image.getContext())
.load(messageList.get(position).getMessage())
.placeholder(R.drawable.ic_image_send_24dp)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(viewHolder2.Image);
break;
}
}
下面是图片布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp">
<RelativeLayout
android:id="@+id/message_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="@drawable/rect_round_primary_color">
<ImageView
android:id="@+id/imageView_message_image"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingTop="8dp"
tools:src="@drawable/ic_image_send_24dp" />
</RelativeLayout>
</FrameLayout>
好的,我得到了解决方案。在 Imageview
android:layout_height="wrap_content"
的布局文件中应该类似于 android:layout_height="250dp"
或
在滑行中使用 override(width, height)
。
所以我正在开发这个聊天应用程序。我可以发送短信和图片。
问题是每当我发送或接收图像时图像变得模糊。虽然当我刷新布局时(我有 SwipeRefreshLayout)图像变得清晰。
我有典型的适配器 class、recyclerView 和图像布局。
这仅发生在 Glide 图片库中,并且与 Picasso 配合得很好。但我只想使用 Glide。这可能是什么问题?
以下是我使用 Glide 的方式:
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
switch (holder.getItemViewType()){
case 1:
ViewHolder1 viewHolder1 = (ViewHolder1)holder;
viewHolder1.Text.setText(messageList.get(position).getMessage());
break;
case 2:
ViewHolder2 viewHolder2 = (ViewHolder2)holder;
Glide.with(viewHolder2.Image.getContext())
.load(messageList.get(position).getMessage())
.placeholder(R.drawable.ic_image_send_24dp)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(viewHolder2.Image);
break;
}
}
下面是图片布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp">
<RelativeLayout
android:id="@+id/message_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="@drawable/rect_round_primary_color">
<ImageView
android:id="@+id/imageView_message_image"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingTop="8dp"
tools:src="@drawable/ic_image_send_24dp" />
</RelativeLayout>
</FrameLayout>
好的,我得到了解决方案。在 Imageview
android:layout_height="wrap_content"
的布局文件中应该类似于 android:layout_height="250dp"
或
在滑行中使用 override(width, height)
。