【问题标题】:Strange issue with loading image from imageview从 imageview 加载图像的奇怪问题
【发布时间】:2016-05-26 13:52:37
【问题描述】:

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

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

我不明白为什么会这样。 我已将视图寻呼机高度设置为 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 不确定。
  • 尝试删除android:scaleType="centerInside"并添加一次android:adjustViewBounds="true"
  • @ShreeKrishna 尝试过仍然面临同样的问题
  • @Nitish 请参阅here,您可能会觉得有帮助。
  • @ShreeKrishna 如果我在 scale 类型中尝试 fitXY 那么它工作正常。

标签: android imageview image-loading


【解决方案1】:

Glide 选项上设置scaleType

v3:

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

v4:

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

【讨论】:

    【解决方案2】:

    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/

    【讨论】:

      猜你喜欢
      • 2014-03-12
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 2010-10-03
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多