我有一个 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
}
}