Android:使用滑动在ListView中加载图像问题

时间:2016-03-19 13:35:55

标签: android imageview android-glide

我使用滑动在ListView中加载图像(ImageView的高度和宽度都是wrap_content)

代码

Glide.with(context).load(rowItem.getPosteduserpostimage()).error(R.drawable.bg_480_800).placeholder(R.drawable.loading_img).into(holder.ivPostedImage);

第一次加载时我正确地获取图像(参见图片)

enter image description here

滚动后,当我再次观看同一张图片时,它会显示为

enter image description here

那么,滚动后如何显示实际图像

注意:我的ImageView高度和宽度是wrap_content

修改 对不起,我忘了提及,我在RelativeLayout中使用了ImageView

XML代码

<RelativeLayout
            android:id="@+id/rl_lv_user_post_adapter_img_holder"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:layout_below="@+id/tv_user_posted_msg_post_items" >

            <ImageView
                android:id="@+id/iv_posted_img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="#ffffff"
                android:contentDescription="@string/cont_desc"/>
        </RelativeLayout>

2 个答案:

答案 0 :(得分:0)

@kiran删除

android:layout_centerInParent="true"

实际上,这就是解决问题并将图像放在中心位置。

答案 1 :(得分:0)

我像这样更改了xml代码

<RelativeLayout
            android:id="@+id/rl_lv_user_post_adapter_img_holder"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_below="@+id/tv_user_posted_msg_post_items" >

            <ImageView
                android:id="@+id/iv_posted_img"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:scaleType="fitCenter"
                android:background="#ffffff"
                android:contentDescription="@string/cont_desc"/>
        </RelativeLayout>

然后它工作正常