Roadies
Roadies

Reputation: 3329

how to set image view in center when i apply pinch zoom on it?

i want to set image on center when i apply properties like this.

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainContainerDialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/color_screen_bg" >

<Button
    android:id="@+id/btnCancel"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@drawable/btn_login_selector"
    android:padding="10dp"
    android:text="@string/title_cancel"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/white" />


    <ImageView
        android:id="@+id/ivProductImageDisplay"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="matrix"
        android:padding="10dp"
        android:layout_above="@+id/btnCancel"
        android:src="@drawable/ic_app_bg_logo" />

  </RelativeLayout>

but my image view always start upper left corner like below images.

enter image description here

i want this image view in center and then apply pinch zoom on this image view.

Upvotes: 0

Views: 1375

Answers (3)

user3996681
user3996681

Reputation:

<ImageView
    android:id="@+id/ivProductImageDisplay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="matrix"
    android:padding="10dp"
    android:layout_above="@+id/btnCancel"
    android:src="@drawable/ic_app_bg_logo"
    android:layout_gravity="center_vertical|center_horizontal"/*The ImageView is Centered by X,Y*/ />

Upvotes: 0

Naveen Tamrakar
Naveen Tamrakar

Reputation: 3339

Use TouchImageView.java in this Code

TouchImageView

Upvotes: 2

Krupa Patel
Krupa Patel

Reputation: 3359

Try this:

Use : RelativeLayout, use: android:layout_centerInParent="true".

or

android:layout_gravity="center" to your ImageView

or

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
<Button
    android:id="@+id/btnCancel"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@drawable/btn_login_selector"
    android:padding="10dp"
    android:text="@string/title_cancel"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/white" />

     <LinearLayout 
            android:orientation="vertical" 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center">
 <ImageView
        android:id="@+id/ivProductImageDisplay"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="matrix"
        android:padding="10dp"
        android:layout_above="@+id/btnCancel"
        android:scaleType="centerInside"
        android:src="@drawable/ic_app_bg_logo" />
</LinearLayout>
</LinearLayout>

Upvotes: 0

Related Questions