I'm programmatically creating two overlapping buttons in a RelativeLayout. Both buttons have different angles so you can press each one. When I press the button on the bottom it comes to front. What should I do so that the button remains behind the other one?
Edit: I forgot to say, that I'm turning the buttons with a RotationAnimation and fillAfter. Without the animation the button remains on the bottom. My min. api is 8, because of that i have to use the anomation.
Edit 2: I'm throwing 78 cards randomly in a RelativeLayout. On that way I'm creating a pile of cards. When I click a card, which is under another card, it comes to front.
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);
}