我写了一个简单的纸牌游戏,用户在三个图像视图(卡片)之一上玩他的卡片,我想通过拖动“桌子”上的 ImageView 来增加玩卡片的可能性(桌子是另一个布局或只是屏幕的另一部分)。
我尝试使用 http://blahti.wordpress.com/2011/01/17/moving-views-part-2/中指示的技术, 但由于它使用 AbsoluteLayout,它对我当前的布局引入了很多限制,更多它需要根据应用程序运行的设备屏幕分辨率进行调整。我想避免这种情况继续使用-如果可能的话-RelativeLayout。也许起点是扩展 ImageView 添加 onTouch 支持,但我无法重现希望的效果(拖动)任何想法或建议或示例代码?谢谢!
只是给出一个想法,这是布局的草稿。下面的 3 张卡片应该通过拖动来移动。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>
<RelativeLayout android:id="@+id/player_cards_layout"
android:layout_width="fill_parent" android:layout_height="150dip"
android:gravity="center_horizontal"
android:background="#55335588"
android:layout_above="@+id/player_cards_layout"
>
<ImageView android:id="@+id/img_pc_card_1"
android:layout_width="100dip" android:layout_height="150dip"
android:src="@drawable/icon"
/>
</RelativeLayout>
<RelativeLayout android:id="@+id/player_cards_layout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:background="#336699"
>
<ImageView android:id="@+id/img_user_card_1"
android:layout_width="100dip" android:layout_height="150dip"
android:src="@drawable/icon"
/>
<ImageView android:id="@+id/img_user_card_2"
android:layout_width="100dip" android:layout_height="150dip"
android:src="@drawable/icon"
android:layout_toRightOf="@+id/img_user_card_1"
/>
<ImageView android:id="@+id/img_user_card_3"
android:layout_width="100dip" android:layout_height="150dip"
android:src="@drawable/icon"
android:layout_toRightOf="@+id/img_user_card_2"
/>
</RelativeLayout>
</RelativeLayout>