[英]Android design game card UI
我需要有關紙牌游戲設計的幫助。
我有一個紙牌向量(玩家紙牌),每個項目都適用於ImageView(已完成並正在工作)。
private Vector<Card> myCards;
我有一個持5個imageView的LinearLayout。
<LinearLayout android:id="@+id/myCardsLayout" android:layout_width="wrap_content" android:layout_height="100dp" android:layout_alignParentBottom="true" android:orientation="horizontal" android:paddingBottom="10dip"> <ImageView android:id="@+id/my_card_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="goToMainMenu" /> <ImageView android:id="@+id/my_card_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="goToMainMenu" /> <ImageView android:id="@+id/my_card_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="goToMainMenu" /> <ImageView android:id="@+id/my_card_4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="goToMainMenu" /> <ImageView android:id="@+id/my_card_5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="goToMainMenu" /> </LinearLayout>
我將在android:onClick函數上實現該功能(goToMainMenu是一個臨時語句)。
任何想法 ? 謝謝!
更新1
public void myCard1OnClick(View view) {
view.setSelected(true);
if(view.isSelected()) {
int y = view.getTop();
view.setTop(y - 30);
}
else{
int y = view.getTop();
view.setTop(y + 30);
}
}
您可以在移動的卡片上設置onclick函數,並為它們提供以x和y坐標為坐標的函數,然后只需向y充氣即可向上移動。
嘗試使用setX()
和setY()
視圖屬性在空間中移動。 關於移動卡的問題,然后將其恢復到原始位置,可能是因為卡組選擇了它不起作用,然后進入else語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.