简体   繁体   中英

Full width image in a ListView

I am using this ImageLoader Library for my ListView. It by default decodes the file to a 70px bitmap. But then I changed it to 1000, and the image I get is proper. The only problem is displaying the image in the ImageView .

The ImageView in the ListItem is like this:

 <ImageView
    android:id="@+id/image"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:scaleType="centerInside" />

This displays an image which is centered in the ImageView, with proper aspect ration(no stretching etc..) and has empty spaces on all sides. The empty spaces might be because of the lower dimensions of the image.

I want the image to take complete width of the screen, and maintain the aspect ration. How do I get it?

I tried:

<ImageView
    android:id="@+id/image"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY" />

But then the image is stretched horizontally and completely out of aspect ration. Looks like its taking the height same as the actual image height but width as fill_parent.

Thank You

Try this:

<ImageView 
            android:id="@+id/background"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/name"
        />

Make android:layout_width="match_parent" . Set height to some arbit but legit value to begin with like android:layout_height="0dp" . And for height, since there is no appropriate scaleType to get the aspect ratio the way you desire (i believe - confirm that developer.android.com/reference/android/widget/…), what you will have to do is in the java file, get the image's width and then set the height according to aspect ratio you need (0.6 in your case).

Try adding this

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"
    />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM