【问题标题】:android image animation in ludo gameludo游戏中的android图像动画
【发布时间】:2013-04-11 22:28:04
【问题描述】:

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

}
}

【问题讨论】:

    标签: android animation imageview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-11-14
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 2023-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多