MainActivity.java
package kantapp.android_animationstutorial; 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 goku; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onZoomClick(View view) { goku=(ImageView)findViewById(R.id.imageView); Animation animation= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom); goku.startAnimation(animation); } public void onClockwise(View view) { goku=(ImageView)findViewById(R.id.imageView); Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.clock); goku.startAnimation(animation); } public void onFadeClick(View view) { goku=(ImageView)findViewById(R.id.imageView); Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade); goku.startAnimation(animation); } public void onBlink(View view) { goku=(ImageView)findViewById(R.id.imageView); Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.blink); goku.startAnimation(animation); } public void onMove(View view) { goku=(ImageView)findViewById(R.id.imageView); Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.move); goku.startAnimation(animation); } public void onSlide(View view) { goku=(ImageView)findViewById(R.id.imageView); Animation animation=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide); goku.startAnimation(animation); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:orientation="vertical" 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="kantapp.android_animationstutorial.MainActivity"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="Animation" android:textAppearance="?android:attr/textAppearanceLarge" /> <ImageView android:id="@+id/imageView" android:layout_width="300dp" android:layout_height="250dp" android:layout_gravity="center_horizontal" android:src="@drawable/goku" /> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/zoom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left|top" android:onClick="onZoomClick" android:text="Zoom" /> <Button android:id="@+id/clock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|top" android:onClick="onClockwise" android:text="ClockWise" /> <Button android:id="@+id/fade" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|top" android:onClick="onFadeClick" android:text="Fade" /> <Button android:id="@+id/blink" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left|center_vertical" android:onClick="onBlink" android:text="Blink" /> <Button android:id="@+id/move" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:onClick="onMove" android:text="Move" /> <Button android:id="@+id/slide" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:onClick="onSlide" android:text="Slide" /> </FrameLayout> </LinearLayout>
slide.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true"> <scale android:duration="500" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/linear_interpolator" android:toXScale="1.0" android:toYScale="0.0" /> </set>
zoom.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:duration="5000" android:fromXScale="0.5" android:fromYScale="0.5" android:pivotX="50%" android:pivotY="50%" android:toXScale="2.0" android:toYScale="2.0"> </scale> </set>
clock.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:duration="5000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" /> </set>
fade.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:duration="2000" android:fromAlpha="1" android:toAlpha="0"> </alpha> <alpha android:duration="2000" android:fromAlpha="0" android:toAlpha="1"> </alpha> </set>
blink.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:duration="600" android:fromAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:repeatCount="10" android:repeatMode="reverse" android:toAlpha="1.0"></alpha> </set>
move.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="800" android:fillAfter="true" android:repeatMode="reverse"> <translate android:fromXDelta="0%p" android:toXDelta="75%p"> </translate> </set>
Download Complete Project:https://userscloud.com/qr4eruffqai0
Only Source Code with image:https://userscloud.com/59m02jaub3fq
Only Source Code with image:https://userscloud.com/59m02jaub3fq
No comments:
Post a Comment