Search code examples
androidresizeimageviewlayoutparamsscaletype

Resize ImageView even if ScaleType


I have a problem, I'm trying to resize a ImageView and its parent container but the problem is that the ImageView has ScaleType:"matrix", and I cant`t resize the image or its container this is my code:

public void resize() {

    LayoutParams contet = relativeLayout.getLayoutParams();
    LayoutParams photo =  image.getLayoutParams();


    int widPhoto = image.getWidth();
    int hePhoto = image.getHeight();

    photo.width = ((widPhoto * 6) / 2);
    photo.height = ((hePhoto * 6) / 2);

    contenedor.width = widPhoto * 2;
    contenedor.height = hePhoto * 2;


    relativeLayout.setLayoutParams(contenedor); 

    image.setLayoutParams(photo );
}

and my xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/containerImg"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="matrix" />

</RelativeLayout>

setLayoutParams() does nothing but remove the property ScaleType if I resize everything correctly, but I cant´t remove that property. Any way to resize? they could put the property ScaleType: NONE? thank you very much and sorry for my bad English


Solution

  • I got the solution, if you are using the Layout ScaleType: matrix you need to use matrix.setScale (); for Resizing