ad728

Thursday, October 12, 2017

AIDE Tutorial - 42 Animation Zoom In And Zoom Out

AIDE Tutorial - 42 Animation Zoom In And Zoom Out

Watch the below video and try yourself
Create an ImageView with id and image sources and add two buttons with onclick method
Main xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:src="@drawable/ic_launcher"
android:id="@+id/mainImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content
android:layout_weight="4"/>
<Button
android:onClick="zoomin"
android:text="Zoom In"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:onClick="zoomout"
android:text="Zoom Out"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Then Create a new folder anim and inside anim folder create two xml file i.e. fade in and fade out. Copy the code below for both xml file.
Zoom_in xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50"
android:toXScale="1.5"
android:toYScale="1.5"></scale></set>
Zoom_out xml
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50"
android:toXScale="0.5"
android:toYScale="0.5"></scale></set>
Add onClick method in Java connect it with animation
package com.kcgroup.AZIO;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.view.animation.*;
public class MainActivity extends Activity
{@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.main);}
public void zoomin(View v){
ImageView image=(ImageView)findViewById(R.id.mainImageView);
Animation an=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_in);
image.startAnimation(an);}
public void zoomout(View v){
ImageView image=(ImageView)findViewById(R.id.mainImageView);
Animation an=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_out);
image.startAnimation(an);}}
Now build the app and it should work fine.
Share:

0 comments:

Post a Comment

Total Pageviews

Sponsor

Sponsor

ad300

Blog Archive