You are on page 1of 2

#1 right-click \res new folder name: anim FINISH

#2 right-click \anim new Android XML File fn: fadein,


select set FINISH
#3 fadein.xml
<set xmlns:android=
"http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="7000"
/>
</set>

10a
8/10b

1
2
3
4
5
6

#4 rotate.xml
<set xmlns:android=
"http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="720"
android:pivotX="50%"
android:pivotY="50%"
android:duration="7000"
/>
</set>

9b
7a

9a

#5 scale.xml
<set xmlns:android=
"http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale=".1"
android:toYScale=".1"
android:toDegrees="720"
android:pivotX="50%"
android:pivotY="50%"
android:duration="7000"
/>
</set>

7b
9c

#6 translate.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:fromYDelta="100%"
android:toXDelta="0%"
#7b
android:toYDelta="0%"
android:toDegrees="720"
android:duration="7000"
ImageView
/>
id = @+id/cdd
</set>
#8
Button b1,b2,b3,b4,b5;
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view =(ImageView) findViewById(R.id.cdd);
final Animation a1 =
AnimationUtils.loadAnimation(this,R.anim.fadein);
final Animation a2 =
AnimationUtils.loadAnimation(this,R.anim.scale);
final Animation a3 =
AnimationUtils.loadAnimation(this,R.anim.rotate);
final Animation a4 =
AnimationUtils.loadAnimation(this,R.anim.translate);
b1
b2
b3
b4
b5

=
=
=
=
=

(Button)
(Button)
(Button)
(Button)
(Button)

findViewById(R.id.btn1);
findViewById(R.id.btn2);
findViewById(R.id.btn3);
findViewById(R.id.btn4);
findViewById(R.id.btn5);

b1.setOnClickListener(new OnClickListener(){
public void onClick(View v){
view.startAnimation(a1);
}
});

Alpha
Scale
Rotate
Translate
Frame-by-Frame

id
id
id
id
id

=
=
=
=
=

Buttons
@+id/btn1
@+id/btn2
@+id/btn3
@+id/btn4
@+id/btn5

b2.setOnClickListener(new OnClickListener(){
public void onClick(View v){
view.startAnimation(a2);
}
});
b3.setOnClickListener(new OnClickListener(){
public void onClick(View v){
view.startAnimation(a3);
}
});
b4.setOnClickListener(new OnClickListener(){
public void onClick(View v){
view.startAnimation(a4);
}
});
b5.setOnClickListener(new OnClickListener(){
public void onClick(View v){
startActivity(new Intent(MainActivity.this,FrameByFrame.class));
}
});
}
#9b
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/one" android:duration="100"/>
<item android:drawable="@drawable/two" android:duration="100"/>
<item android:drawable="@drawable/three" android:duration="100"/>
<item android:drawable="@drawable/four" android:duration="100"/>
<item android:drawable="@drawable/five" android:duration="100"/>
<item android:drawable="@drawable/six" android:duration="100"/>
</animation-list>
#9c
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imgview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="143dp"
/>
</RelativeLayout>
#10a right-click \com.androidexercises.myanimations new Class fn: FrameByFrame FINISH
public class FrameByFrame extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.framebyframe);
ImageView image = (ImageView) findViewById(R.id.imgview);
image.setImageBitmap(null);
image.setBackgroundResource(R.drawable.animated);
final AnimationDrawable imganim=(AnimationDrawable) image.getBackground();
image.post(new Runnable(){
public void run(){
if(imganim!=null)
imganim.start();
}
});
}
}
#10b (append inside onCreate() method MainActivity.java)
b5.setOnClickListener(new OnClickListener(){
public void onClick(View v){
startActivity(new Intent(MainActivity.this,FrameByFrame.class));
}
});

You might also like