Welcome back to another Android animation effect tutorial. In this tutorial I'm gonna show you how to set android move up xml animation effect. By move up animation we can move up any text, images or any other objects of our android apps. Here is an example you are seeing.
Step 1:
First of all create a animation resource file under anim folder. Here I've created move_up.xml that are showing in following screenshot.
Step 2:
Write down the following code in move_up.xml file.
move_up.xml
Step 1:
First of all create a animation resource file under anim folder. Here I've created move_up.xml that are showing in following screenshot.
move_up.xml animation resource file |
Step 2:
Write down the following code in move_up.xml file.
move_up.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="3000" android:fromYDelta="800" android:toYDelta="0" android:repeatCount="3" /> </set>
Note: To set the animation from the left corner or right corner you have to add following code in move
android:fromXDelta="-600" android:toXDelta="0"
Step 3:
Set an Image or Text in the activity_main.xml . Here I set an Image with ImageView with the id iv. The image is located at drawable folder. To clear look at the image below.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <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" tools:context="com.example.hp.symonapps.MainActivity"> <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> </RelativeLayout>
MainActivity.java
package com.example.hp.symonapps; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create ImageView object then cast the ImageView ImageView iv = (ImageView) findViewById(R.id.iv); //set the animation Animation anim = AnimationUtils.loadAnimation(this,R.anim.move_up); iv.setAnimation(anim); } //onCreate end }
Comments
Post a Comment