我正在为Android创建游戏,玩家可以选择从棋盘中选择一些骰子。有没有一种方法可以增加微小的视觉效果,从而告知玩家他选择了哪个骰子?每个ImageView都有一个侦听器。
骰子的Pic。
最佳答案
对于按下状态和正常状态,将需要单独的图像。
例如
按下状态图片=>按下_骰子_img.jpg
normal_state图片=> normal_dice_img.jpg
那么您将必须在res / drawable文件夹中使选择器文件名为dice_image_view_selector.xml,如下所示
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/pressed_dice_image" />
<item android:state_pressed="true" android:drawable="@drawable/pressed_dice_image" />
<item android:drawable="drawable/normal_dice_image" />
</selector>
然后像这样应用于您的每个图像视图
android:background="dice_image_view_selector.xml"
关于android - 在我的ImageView中添加“点击效果”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24221893/