2016-05-26 23 views
0

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

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

我不明白为什么会发生这种情况。 我已将视图寻呼机高度设置为140dp。对于viewpager适配器的XML如下:

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

尝试scaleType不确定。 – Nisarg

+0

尝试删除'android:scaleType =“centerInside”'并添加'android:adjustViewBounds =“true”'一次, –

+0

@ShreeKrishna尝试仍然面临同样的问题 – Nitish

回答

0

坐落在Glide选项scaleType

V3:

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

<?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加载图像

V4:

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