olegario
olegario

Reputation: 742

Android:ScaleType="fitXY" not working for all images

I'm having a strange behaviour on my Android application. I have this XML configuration

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

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

     <TextView
         android:id="@+id/content"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_margin="@dimen/text_margin"
        android:textAppearance="?attr/textAppearanceListItem" />
</LinearLayout>

But when I run the application the result is this

enter image description here

The images 1', 2' and 3' are correct, but why the third image of the first row is not correct? Also, there is another images on same screen and in other columns with the same problem. All images have the same size

Upvotes: 1

Views: 3719

Answers (2)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

  1. Set width match_parent
  2. Add android:adjustViewBounds.

Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

 <ImageView
         android:id="@+id/thumbnail"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:adjustViewBounds="true"
         android:scaleType="fitXY"/>

Upvotes: 3

Sakura Fukuyoshi
Sakura Fukuyoshi

Reputation: 1471

Did you try to make the linearlayout set to match_parent in width?

Upvotes: 2

Related Questions