2

I am using Zoom effect with ImageView so I need to use scaletype=matrix. Now, I want to set Center position to ImageView but I am not able to set it.

Please help me regarding this.

layout.xml :

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

    <ImageView
        android:id="@+id/imgImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/imgdesc"
        android:scaleType="matrix"
        android:src="@drawable/ic_answer" />

</RelativeLayout>
Jeeten Parmar
  • 5,568
  • 15
  • 62
  • 111

5 Answers5

1

try this to your ImageView

  android:layout_centerInParent="true"
M D
  • 47,665
  • 9
  • 93
  • 114
0

try below code:

android:scaleType="centerInside"

or

android:scaleType="fitCenter"

or

android:scaleType="centerCrop"
duggu
  • 37,851
  • 12
  • 116
  • 113
0

Under android:scaleType="matrix" circumstance, the only way I found is to use Matrix to set ImageView position, use the following code:

Matrix matrix = new Matrix();
matrix.postTranslate(screen_width/2, screen_height/2);
imageView.setImageMatrix(matrix);
einverne
  • 6,454
  • 6
  • 45
  • 91
0

I had the sameproblem. Eventually I Gave up for using Matrix and replaced it with this:

android.view.ViewGroup.LayoutParams params = imageView.getLayoutParams();
params.height = desiredHeight;
params.width = desiredWid;
imageView.setLayoutParams(params);
Sergei Bubenshchikov
  • 5,275
  • 3
  • 33
  • 60
-1

try this,

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

    <ImageView
        android:id="@+id/imgImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:scaleType="matrix"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

this may help you

Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19
  • 2
    This will work for sure, but then `ImageView` sets its boundary and so It wont allow user to zoom Image outside of its boundary. – Jeeten Parmar May 20 '14 at 09:00