开发者

ListFragment images change size

I have a ListFragment with a custom ListAdapter that lazy loads images and displays a view with the image on the left and some text on the right. The custom list item I'm using looks like this:

<?xml ve开发者_Python百科rsion="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image"
        android:maxWidth="80dp"
        android:adjustViewBounds="true" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:textSize="16sp" 
        android:gravity="left|center_vertical" />

</LinearLayout>

This is all working fine, but when I click a list item and then click back, most times the list displays with the images at their full size, not at 80dp width as specified. If I wait a while before pressing back, the list sometimes loads correctly.

Does anyone know how I could fix this? I want the images to always display at 80dp width. Thanks.


This is how I use images with different widths and heights. Force every image to 85x85, cropped.

<ImageView
        android:src="@drawable/some_img"
        android:layout_width="85dip"
        android:layout_height="85dip"
        android:scaleType="centerCrop" 
    />

You might consider using either centerCrop or centerInside.

I wouldn't be surprised if android:adjustViewBounds="true" is causing the issue you are seeing.

Another possible culprit is that you are setting android:layout_height="fill_parent" in the TextView which should be wrap_content

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜