1

我需要对卡片进行动画处理,从其原始位置移动并降落在另一个预定义的图像视图之上(表示卡片表中的卡片堆栈)

    public static ImageView REFERENCE_IMAGE_FOR_ANIMATION;
REFERENCE_IMAGE_FOR_ANIMATION = (ImageView) findViewById(R.id.cardpile);

    public void deckButtonOnClick(View v) {
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageResource(DECK.takeCard());
    imageView.setAdjustViewBounds(true);
    imageView.setLayoutParams(PARAMS);
    imageView.setTag("0");
    imageView.setOnClickListener(new MyOnClickListener());

    ((LinearLayout) findViewById(R.id.innerLinearLayout))
            .addView(imageView);

}

我的代码MyOnClickListener如下:

public class MyOnClickListener{
Animation standardPosition = new TranslateAnimation(0, 0, 0, -25f);

@Override
public void onClick(View v) {
    Animation standardPosition;

    Animation risedPositionAndChosen;

    if (v.getTag().toString().equalsIgnoreCase("0")) {
        standardPosition = new TranslateAnimation(0, 0, 0, -25f);
        standardPosition.setDuration(400);
        standardPosition.setFillAfter(true);
        v.setTag("1");
        v.startAnimation(standardPosition);

    } else if (v.getTag().toString().equalsIgnoreCase("1")) {
        risedPositionAndChosen = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_PARENT,    Game.REFERENCE_IMAGE_FOR_ANIMATION.getRight()
                - v.getRight(), Animation.RELATIVE_TO_SELF,
                0,Animation.RELATIVE_TO_PARENT, -Game.REFERENCE_IMAGE_FOR_ANIMATION.getTop());
        risedPositionAndChosen.setDuration(400);
        risedPositionAndChosen.setFillAfter(true);
        v.setTag("0");
        v.startAnimation(risedPositionAndChosen);

    } else if (v.getTag().toString().equalsIgnoreCase("2")) {

    }
    ((View) v.getParent()).invalidate();
}

}

这是OnClickListener我需要更改的第一个“else if”语句。

REFERENCE_IMAGE_FOR_ANIMATION = (ImageView) findViewById(R.id.cardpile);是我需要“登陆”的卡。

我的游戏屏幕布局包含一个嵌套ScrollViewLinearLayout内部。当动画开始时,卡片会“滑入”层次结构中较高的布局。我应该怎么做才能让它“浮在上面”?

4

0 回答 0