import
android.app.Activity;
import
android.view.ViewGroup.LayoutParams;
import
android.view.animation.Animation;
import
android.view.animation.TranslateAnimation;
import
android.widget.ImageView;
import
android.widget.RelativeLayout;
public
class
Ball
extends
Activity
{
private
String name;
private
int
rand;
ImageView img;
RelativeLayout rel = (RelativeLayout)findViewById(R.id.GameView);
public
Ball(
int
num)
{
rand = (
int
)(Math.random() *
500
+
1
);
img =
new
ImageView(
this
);
img.setLayoutParams(
new
LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
setName(num);
Animation ani =
new
TranslateAnimation(rand, rand, -
500
,
1700
);
ani.setDuration(
5000
);
img.setAnimation(ani);
status =
"S"
;
speed =
10000
;
}
public
void
setName(
int
num)
{
switch
(num)
{
case
1
:
this
.name =
"Red"
;
img.setBackgroundResource(R.drawable.red);
rel.addView(img);
break
;
case
2
:
this
.name =
"Blue"
;
img.setBackgroundResource(R.drawable.blue);
rel.addView(img);
break
;
case
3
:
this
.name =
"Green"
;
img.setBackgroundResource(R.drawable.green);
rel.addView(img);
break
;
case
4
:
this
.name =
"Violet"
;
img.setBackgroundResource(R.drawable.violet);
rel.addView(img);
break
;
}
}
}