Search code examples
androidscaleandroid-imageview

ImageView source will not scale


This should be easy, but I could not find a solution. I have three ImageViews inside a RelativeLayout. These ImageViews will represent three buttons (I tried using ImageButton as well, same problem there).

Thing is, the three sources, bluered, green and blueyellow are *.png files of some size (in this case larger than the buttons/ImageViews size). I want these sources to scale to fit into the ImageViews and use the dimension of buttonsleftRightMenu. The sources are quadratic images, so this should be easy. Where do I go wrong?

xml file:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@integer/leftMenuID"
>

<ImageView 
    android:layout_width="@dimen/buttonsLeftRightMenu"
    android:layout_height="@dimen/buttonsLeftRightMenu"
    android:src="@drawable/bluered"
    android:id="@integer/leftMenuButton1ID"
    android:clickable="true"
    android:contentDescription="@string/leftMenuButton1ContentDescription"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:scaleType="fitCenter"
    android:adjustViewBounds="true"
 />

 <ImageView 
    android:layout_width="@dimen/buttonsLeftRightMenu"
    android:layout_height="@dimen/buttonsLeftRightMenu"
    android:id="@integer/leftMenuButton2ID"
    android:clickable="true"
    android:src="@drawable/green"
    android:background="@color/transparent"
    android:contentDescription="@string/leftMenuButton2ContentDescription"
    android:layout_below="@integer/leftMenuButton1ID"
    android:scaleType="fitCenter"
 />

 <ImageView 
    android:layout_width="@dimen/buttonsLeftRightMenu"
    android:layout_height="@dimen/buttonsLeftRightMenu"
    android:id="@integer/leftMenuButton3ID"
    android:clickable="true"
    android:src="@drawable/blueyellow"
    android:background="@color/transparent"
    android:contentDescription="@string/leftMenuButton3ContentDescription"
    android:layout_below="@integer/leftMenuButton2ID"
    android:scaleType="fitCenter"
 />

</RelativeLayout>

Solution

  • This was just a stupid mistake. The code works perfectly, just remember to inflate the corrext xml file.