我只想使用动画在Ludo 板上从下到上、从左到右翻译图像(令牌) 。为此,我已经从每个标记(红色、蓝色、黄色、绿色)将移动的每个 ImageView 的坐标中获取了坐标,但现在我被卡住了;接下来我该怎么做?我是 Android 动画的新手。我怎么能那样做?
这是我的数组索引代码:
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.start );
double aPowersOfTwo[] = new double[60];
aPowersOfTwo[0]=Math.pow(81,263);
aPowersOfTwo[1]=Math.pow(50,262);
aPowersOfTwo[2]=Math.pow(50,231);
aPowersOfTwo[3]=Math.pow(80,227);
}
我的黄色令牌的Java代码是
switch(rand.nextInt(6) + 1)
{
case 1:
diceImage.setImageResource(R.drawable.dice_one);
yellowToken.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.yellow_token9:
Animation animation = new TranslateAnimation(0,80,0,48);
animation.setDuration(1500);
animation.setFillAfter(true);
yellowToken.startAnimation(animation);
yellowToken.setVisibility(0);
break;
}
}});
case 2:
diceImage.setImageResource(R.drawable.dice_two);
Log.d("dice", "2");
break;
case 3:
diceImage.setImageResource(R.drawable.dice_three);
Log.d("dice", "3");
break;
case 4:
diceImage.setImageResource(R.drawable.dice_four);
Log.d("dice", "4");
break;
case 5:
diceImage.setImageResource(R.drawable.dice_five);
Log.d("dice", "5");
break;
case 6:
diceImage.setImageResource(R.drawable.dice_six);
yellowToken.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.yellow_token9:
Animation animation = new TranslateAnimation(0,80,0,48);
animation.setDuration(1500);
animation.setFillAfter(true);
yellowToken.startAnimation(animation);
yellowToken.setVisibility(0);
break;
}
}});
我的xml代码是
<ImageView
android:id="@+id/yellow_token9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginTop="222dp"
android:clickable="true"
android:background="@drawable/yellow"/>