Archie.bpgc Archie.bpgc - 1 month ago 20
Android Question

Drag,Zoom or Rotate an ImageView

Here is a class which performs Drag, Zoom and Rotate of an ImageView.

xml

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

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="matrix"
android:src="@drawable/butterfly" />

</FrameLayout>


But it was all done on the Matrix of the ImageView using the
imageView.setImageMatrix(matrix);


Not the actual image view.

Hence the below results:

Initial ImageView:

enter image description here

On Dragging right:

enter image description here

On Zooming in:

enter image description here

On Rotating:

enter image description here

Is there a way I can modify the ImageView to change as per it's Matrix?

Answer

You can call View.setRotation(), View.setPivotX(), View.setPivotY(), View.setScaleX(), View.setScaleY(), View.setTranslationX() and View.setTranslationY() ond any View including an ImageView.

Reference: http://developer.android.com/reference/android/view/View.html

Comments