从imageview加载图像的奇怪问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从imageview加载图像的奇怪问题相关的知识,希望对你有一定的参考价值。

我在我的应用程序中使用Glide从服务器加载图像。图像显示在ViewPager中。我面临一个奇怪的问题。第一次加载图像时,显示如下:enter image description here

但是当我滚动页面并返回到原始页面时,它会正确显示。 enter image description here

我不明白为什么会这样。我已将视图寻呼机高度设置为140dp。 viewpager适配器的xml如下:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_banner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:background="@drawable/car_bg"
tools:ignore="ContentDescription" />

从url加载图片的代码:

Glide.with(ctx).load(banner.getImgScrollBanner()).placeholder(R.drawable.loading_spinner).error(R.drawable.car_bg).into(bannerView);
答案

scaleType选项上设置Glide

采取:

Glide.with(ctx).load(banner.getImgScrollBanner()).centerInside().placeholder(R.drawable.loading_spinner).error(R.drawable.car_bg).into(bannerView);

B4

Glide.with(ctx)
     .apply(new RequestOptions()
              .centerCrop()
              .placeholder(R.drawable.loading_spinner)
              .error(R.drawable.car_bg))
     .load(banner.getImgScrollBanner())
     .into(bannerView);
另一答案

android使用Picasso库加载图像

Picasso.with(MainActivity.this)
            .load(R.drawable.ic_launcher_foreground)

您甚至可以从服务器URL加载图像

             .load("your image url")

更多访问。

http://www.androidcoding.in/2017/12/10/android-tutorial-picasso-library-load-image-using-picasso/

以上是关于从imageview加载图像的奇怪问题的主要内容,如果未能解决你的问题,请参考以下文章

Android Lollipop 问题 - 无法将图像从相机加载到 ImageView

如何从 URL 将图像加载到 imageView? [复制]

如何将图像文件加载到 ImageView?

使用 AsyncImageView 将图像加载到 ImageView 宽度

ImageView 加载本地图像,但不从 URL

从图库中获取图像以在片段中的图像视图中设置? [复制]