Tahlil
Tahlil

Reputation: 2721

Zooming an imageview to the full screen

I have a xml. Which has a relative layout. And on that layout there are some TextFields. In the middle of the relative layout there is an ImageView. I want to pinch zoom that imageView so that it can even be zoomed to the full screen. Now I can only zoom inside the ImageView. Like the ImageView is a screen and the zooming occurs only inside it. But I want to zoom relative to the whole screen. When the image is zoomed I want the TextFields to maintain there position but they should be covered when the image is zoomed. Is there any way to do it? Thanks.

Upvotes: 2

Views: 4835

Answers (1)

mdDroid
mdDroid

Reputation: 3195

create zoom_in.xml in your anim folder in res and write following code

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >

<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="3"
    android:toYScale="3" >
</scale>

and in your code write the following code

public class ZoomInActivity extends Activity implements AnimationListener {

ImageView imgPoster;
Button btnStart;

// Animation
Animation animZoomIn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_zoom_in);

    imgPoster = (ImageView) findViewById(R.id.imgLogo);
    btnStart = (Button) findViewById(R.id.btnStart);

    // load the animation
    animZoomIn = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.zoom_in);

    // set animation listener
    animZoomIn.setAnimationListener(this);

    // button click event
    btnStart.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // start the animation
            imgPoster.startAnimation(animZoomIn);
        }
    });

}

@Override
public void onAnimationEnd(Animation animation) {
    // Take any action after completing the animation

    // check for zoom in animation
    if (animation == animZoomIn) {          
    }

}

@Override
public void onAnimationRepeat(Animation animation) {
    // TODO Auto-generated method stub

}

@Override
public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub

}

}

and your activity_zoom_in.xml is

<?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"
android:background="#000000"
android:gravity="center">

<ImageView android:id="@+id/imgLogo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/man_of_steel"
    android:layout_centerInParent="true"/>

<Button android:id="@+id/btnStart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start Animation"
    android:layout_marginTop="30dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="20dp"/>

</RelativeLayout>

Upvotes: 1

Related Questions