how to create image scaling animation in android apps




Learn how to create image scaling animation in android studio.It uses Animation class. You can use this in any app to make your app attractive and beautiful.



MainActivity.java


 package com.singh.jassi.myanimation;  
 import android.support.v7.app.AppCompatActivity;  
 import android.os.Bundle;  
 import android.view.View;  
 import android.view.animation.Animation;  
 import android.view.animation.AnimationUtils;  
 import android.widget.Button;  
 import android.widget.ImageView;  
 public class MainActivity extends AppCompatActivity {  
   ImageView imageView;  
   Button b1;  
   Animation animation;  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
     imageView=(ImageView)findViewById(R.id.imageView);  
     b1=(Button)findViewById(R.id.button);  
     imageView.setImageResource(R.drawable.myimage);  
     animation= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.scale);  
   }  
   public void startAnimation(View view)  
   {  
     imageView.startAnimation(animation);  
   }  
 }  



activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>  
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:app="http://schemas.android.com/apk/res-auto"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:id="@+id/activity_main"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   android:paddingBottom="@dimen/activity_vertical_margin"  
   android:paddingLeft="@dimen/activity_horizontal_margin"  
   android:paddingRight="@dimen/activity_horizontal_margin"  
   android:paddingTop="@dimen/activity_vertical_margin"  
   tools:context="com.singh.jassi.myanimation.MainActivity">  
   <ImageView  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     app:srcCompat="@drawable/myimage"  
     android:id="@+id/imageView"  
     android:layout_above="@+id/button"  
     android:layout_alignParentStart="true"  
     android:layout_marginBottom="92dp" />  
   <Button  
     android:text="Start animation"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_marginBottom="51dp"  
     android:id="@+id/button"  
     android:layout_alignParentBottom="true"  
     android:layout_centerHorizontal="true"  
     android:onClick="startAnimation"  
     />  
 </RelativeLayout>  


scale.xml ( animation resource file in anim floder)

 <?xml version="1.0" encoding="utf-8"?>  
 <set xmlns:android="http://schemas.android.com/apk/res/android">  
   <scale  
     android:duration="6000"  
     android:fromXScale="1.0"  
     android:fromYScale="1.0"  
     android:interpolator="@android:anim/linear_interpolator"  
     android:toXScale="1.0"  
     android:toYScale="0.0"  
     ></scale>  
 </set>  


AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>  
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="com.singh.jassi.myanimation">  
   <application  
     android:allowBackup="true"  
     android:icon="@mipmap/ic_launcher"  
     android:label="@string/app_name"  
     android:supportsRtl="true"  
     android:theme="@style/AppTheme">  
     <activity android:name=".MainActivity">  
       <intent-filter>  
         <action android:name="android.intent.action.MAIN" />  
         <category android:name="android.intent.category.LAUNCHER" />  
       </intent-filter>  
     </activity>  
   </application>  
 </manifest>  
  

Comments

  1. I really like and appreciate your work which is about animation. The article you have shared here is great. I read your post with carefully, the points you mentioned can be very helpful. It is nice seeing your wonderful post. Best Animation, Vfx, Gaming Course In Delhi

    ReplyDelete

Post a Comment

Popular posts from this blog

File handling

Getting started with android app development

How to create android Text To Speech app