0

I have An imageView with android:scaleType="matrix"

<ImageView
    android:id="@+id/imageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="20dp"
    android:scaleType="matrix"
    android:src="@drawable/ic_launcher" />

I want to drag this ImageView to left to look at the parts of image which were off screen.

In other words I want to move this image to the point where I mark the point on ImageView.

Please help. Thanks

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
Imran Ahmad
  • 85
  • 11

1 Answers1

0

Put your Imageview Inside Framelayout and use following code to move it :

Java Code:

_frameLayout.setX(Position);

_frameLayout.setY(Position);

Example XML :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_material_dark" >

    <ImageView 
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@drawable/ic_launcher"/>

    <FrameLayout
        android:id="@+id/framelayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:background="#ffffff" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/img"
                android:layout_width="110dp"
                android:layout_height="200dp"
                android:layout_centerHorizontal="true"
                android:background="@drawable/ic_launcher" />
        </RelativeLayout>
    </FrameLayout>
  • How i calculate X and Y position? – Imran Ahmad Jun 04 '15 at 14:27
  • Can you please tell me?? – Imran Ahmad Jun 04 '15 at 18:05
  • float yAxis = 0.0f; int dragDistance = 200; yAxis = event.getRawY() - dragDistance * 3 / 2; int mathValue = (int) Math.round(yAxis); _frameLayout.setY(mathValue); This will move your frame in vertical – Syed Nazar Muhammad Jun 05 '15 at 06:20
  • This code move the whole framelayout i just want to move imgae ... i also applied panning and zooming functionality on that image. i just want that this image behave like google map. onTuch event when i drag that image to left i can see the hidden part of that image but the only thing i want the auto move the image to the current location (which was hidden). hope you understand my question. Thanks in advance – Imran Ahmad Jun 05 '15 at 11:18
  • @ImranAhmad I just showed a way, and this is not the whole layout, here framelayout is just a small part of the layout & in that framelayout only imageview is present. Using this example u can smartly design ur layout. Here I showed framelayout just to show how to move your imageview over layout – Syed Nazar Muhammad Jun 11 '15 at 07:04