ludo游戏中的android图像动画

ludo游戏中的android图像动画,android,animation,imageview,Android,Animation,Imageview,我有一个ludo板的布局,在其中我想根据骰子的编号移动我的代币。例如,如果骰子卷编号为6,我们将单击哪个图像视图应移动6,如果是4,则根据ludo板移动4个位置。 我的问题是如何确定所有棋盘的位置,以便我们的令牌根据骰子编号移动。 这是我的活动 public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView( R.layout.firs

我有一个ludo板的布局,在其中我想根据骰子的编号移动我的代币。例如,如果骰子卷编号为6,我们将单击哪个图像视图应移动6,如果是4,则根据ludo板移动4个位置。 我的问题是如何确定所有棋盘的位置,以便我们的令牌根据骰子编号移动。 这是我的活动

public void onCreate( Bundle savedInstanceState )
{
    super.onCreate( savedInstanceState );
    setContentView( R.layout.first_page );

    ImageView iv = new ImageView(this);
   iv.setImageResource(R.drawable.token);




    rollerButton = (Button)findViewById( R.id.rolldice );
    image = (ImageView) findViewById(R.id.dice);
    board = (ImageView) findViewById(R.id.board);

    rollerButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch(v.getId())
            {
            case R.id.rolldice:
                Log.d("clicked", "button");
                startAnimation(image);

            }

        }
    });

    board.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //Choose which motion action has been performed


            switch(event.getAction())
            {
            case MotionEvent.ACTION_DOWN:
                //Get X, Y coordinates from the ImageView
                X = (int) event.getX();
                Y = (int) event.getY();

                position1=new ArrayList<Integer>();


                position1.add(X);
                position1.add(Y);



                for(int i=0;i<position1.size();i++)
                {
                    position1.get(i);
                }

                Log.d("X COordinate",""+X);
                Log.d("Y COordinate",""+Y);

                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
            }
            return true;
        }
});





}


public void startAnimation(View view) {

    switch (view.getId()) {


    case R.id.dice:

        Animation animation = new TranslateAnimation(0, 100,0, -100);
        animation.setDuration(1500);
        animation.setFillBefore(true);
        image.startAnimation(animation);
        image.setVisibility(0);
        break;      

    default:
        break;
    }

}

@Override
public void onAnimationEnd(Animation animation) {
    // TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
    // TODO Auto-generated method stub

}

@Override
public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub

}
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.first_页);
ImageView iv=新的ImageView(本);
iv.setImageResource(R.drawable.token);
rollerButton=(按钮)findViewById(R.id.rolldice);
image=(ImageView)findviewbyd(R.id.dice);
board=(ImageView)findViewById(R.id.board);
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
开关(v.getId())
{
案例R.id.rolldice:
Log.d(“单击”、“按钮”);
startAnimation(图像);
}
}
});
board.setOnTouchListener(新的OnTouchListener(){
@凌驾
公共布尔onTouch(视图v,运动事件){
//选择已执行的运动动作
开关(event.getAction())
{
case MotionEvent.ACTION\u DOWN:
//从ImageView获取X,Y坐标
X=(int)event.getX();
Y=(int)event.getY();
位置1=新的ArrayList();
位置1.添加(X);
位置1.添加(Y);

对于(int i=0;i您可以为所有位置创建一个坐标x,y的二维数组类,并在imageview中使用动画。然后将根据该类的索引进行调用