Hier habe ich eine einfache Android-Application gebastelt. Es handelt sich um eine animierte Münze, die zufällig Kopf oder Zahl anzeigt.

Coin App
Video
Source-Code
package tk.pixilab.android;
import java.util.Random;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class CoinActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Drawable kopf = (Drawable)getResources().getDrawable(R.drawable.coin_1);
final Drawable zahl = (Drawable)getResources().getDrawable(R.drawable.coin_5);
final AnimationDrawable animation = (AnimationDrawable)getResources().getDrawable(R.drawable.coin_animation);
final Button btn_coin
= (Button)findViewById
(R.
id.
main_btn_coin); btn_coin.setOnClickListener(new OnClickListener() {
@Override
public void onClick
(View v
) { int random
= animation.
isRunning()?new Random().
nextInt(2
):2; switch(random) {
case 0:{
animation.stop();
btn_coin.setBackgroundDrawable(kopf);
break;
}
case 1:{
animation.stop();
btn_coin.setBackgroundDrawable(zahl);
break;
}
case 2:{
btn_coin.setBackgroundDrawable(animation);
animation.start();
break;
}
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@drawable/background"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/main_btn_coin"
android:background="@drawable/coin_1"/>
</LinearLayout>
<?xml version="1.0" encoding="UTF-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/background_img" android:tileMode="repeat"/>
<?xml version="1.0" encoding="UTF-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/coin_1" android:duration="50" />
<item android:drawable="@drawable/coin_2" android:duration="50" />
<item android:drawable="@drawable/coin_3" android:duration="50" />
<item android:drawable="@drawable/coin_4" android:duration="50" />
<item android:drawable="@drawable/coin_5" android:duration="50" />
<item android:drawable="@drawable/coin_6" android:duration="50" />
<item android:drawable="@drawable/coin_7" android:duration="50" />
<item android:drawable="@drawable/coin_8" android:duration="50" />
</animation-list>
Resources
drawable
svn: http://tk-pixilab-adroid-coin.googlecode.com/svn/trunk