重叠的旋转按钮 - 点击后面的一个来到前面

时间:2014-03-14 18:08:02

标签: android animation button overlap

我以编程方式在RelativeLayout中创建两个重叠按钮。两个按钮都有不同的角度,因此您可以按下每个按钮。当我按下底部的按钮时,它就会出现在前面。我应该怎么做才能让按钮留在另一个按钮后面?

编辑: 我忘了说,我用RotationAnimation转动按钮并填充后。如果没有动画,按钮仍保留在底部。我的分钟。 api是8,因为我必须使用anomation。

编辑2: 我在RelativeLayout中随机丢了78张牌。就这样,我创造了一堆牌。当我点击另一张卡片下的卡片时,它会出现在前面。

    ImageButton card;
    Random random = new Random();
    RotateAnimation cardRotation;
    int x = 0;
    int y = 0;
    int angle = 0;

    for(int i=0;i<78;i++) {
        x = random.nextInt(fieldWidth + 1 - cardHeight - cardHeight / 4) + cardHeight / 4;
        y = random.nextInt(fieldHeight + 1 - cardHeight - cardHeight / 2) + cardHeight / 2;
        angle = random.nextInt(360 + 1);
        angle = random.nextInt(360 + 1);

        card = new ImageButton(this);
        card.setScaleType(ScaleType.FIT_XY);
        card.setImageResource(R.drawable.card_back);

        RelativeLayout.LayoutParams cardParams = new RelativeLayout.LayoutParams(cardWidth, cardHeight);
        cardParams.leftMargin = x;
        cardParams.topMargin = y;
        card.setLayoutParams(cardParams);

        cardRotation = new RotateAnimation(0, angle, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        cardRotation.setDuration(0);
        cardRotation.setFillAfter(true);
        card.startAnimation(cardRotation);

        card.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cardClicked(v);
            }
        });

        cardField.addView(card);
    }

1 个答案:

答案 0 :(得分:1)

尝试使用后面的按钮。

android:focusableInTouchMode="false"