我试图让我的游戏中的扑克牌重叠,以便只看到一张牌的前半部分,而另一半被下一张牌覆盖。唯一应该完全可见的卡片将是最后一张/最右边的卡片。
我已将以下代码与 framelayout 和 relativelayout 一起使用,但无济于事。谁能提供一些建议?
public int shouldShow(int numberOfCards, int card, int id)
{
if(card == -1)
hide(id);
else
{
findViewById(id).setBackgroundDrawable(deckimages[card]);
//findViewById(id).offsetLeftAndRight(findViewById(id).getWidth()* numberOfCards / 2);
show(id);
//findViewById(id).setPadding(findViewById(id).getWidth()* numberOfCards / 2, 0,0,0);
return numberOfCards+1;
}
return numberOfCards;
}
我尝试使用填充和偏移方法,这两种方法都不适合我。但我也注意到 getwidth() 和 getmeasuredwidth() 方法返回 0。
关于我应该使用哪种布局以及为什么 getwidth 函数不起作用的任何建议?
xml代码在下面......会有比这更多的图像,但这是我正在测试的
<RelativeLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/RelativeLayout1">
<ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<ImageView android:id="@+id/imageView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</RelativeLayout>