ad728

Friday, December 29, 2017

AIDE Tutorial - 43 Animation Bounce Top Bottom Left Right

AIDE Tutorial - 43 Animation Bounce Top Bottom Left Right

Watch the video below

Main Activity.java
package com.kcgroup.animbounce;
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 top(View v){
ImageView image=(ImageView)findViewById(R.id.mainImageView);
Animation an=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.bounce_top);
image.startAnimation(an);}
public void bottom(View v){ImageView image=(ImageView)findViewById(R.id.mainImageView);
Animation an=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.bounce_bottom);
image.startAnimation(an);}
public void right(View v){
ImageView image=(ImageView)findViewById(R.id.mainImageView);
Animation an=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.bounce_right);
image.startAnimation(an);}
public void left(View v){ImageView image=(ImageView)findViewById(R.id.mainImageView);
Animation an=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.bounce_left);image.startAnimation(an);}}

Main.xml
<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:layout_weight="4"
android:id="@+id/mainImageView"
        android:src="@drawable/ic_launcher"
        android:layout_width="match_parent"        android:layout_height="wrap_content" />
<Button
android:text="Top"
android:onClick="top"
android:layout_width="match_parent"        android:layout_height="wrap_content" />
<Button
android:text="Bottom"
android:onClick="bottom"
android:layout_width="match_parent"        android:layout_height="wrap_content" />
<Button
android:text="Right"
android:onClick="right"
android:layout_width="match_parent"        android:layout_height="wrap_content" />
<Button
android:text="Left"
android:onClick="left"
android:layout_width="match_parent"        android:layout_height="wrap_content" />
</LinearLayout>
Create a new folder anim add four xml
Bounce_Bottom.xml
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/bounce_interpolator">
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="0"
android:toXScale="1"
android:toYScale="1"></scale></set>
Bounce_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/bounce_interpolator">
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="0"
android:toYScale="1"></scale></set>
Bounce_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/bounce_interpolator">
<scale
android:duration="1000"
android:fromXScale="0"
android:fromYScale="1"
android:toXScale="1"
android:toYScale="1"></scale></set>

Bounce_Top.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
   android:fillAfter="true"
   android:interpolator="@android:anim/bounce_interpolator">
   <scale
   android:duration="1000"
   android:fromXScale="1"
   android:fromYScale="1"
   android:toXScale="1"
   android:toYScale="0"></scale></set>

Share:

0 comments:

Post a Comment

Total Pageviews

Sponsor

Sponsor

ad300

Blog Archive