android - 在我的 ImageView 中添加一个 "clicked effect"

标签 android imageview visual-effects

我正在为 Android 创建一款游戏,玩家可以选择从棋盘上挑选一些骰子。有没有办法添加一个小的视觉效果来告知玩家他选择了哪个骰子?每个 ImageView 都有一个监听器。

Pic的骰子。

最佳答案

您将需要用于按下和正常状态的单独图像。

例如

pressed_state 图片 => pressed_dice_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>

然后像这样应用到你的每个 ImageView

android:background="dice_image_view_selector.xml"

关于android - 在我的 ImageView 中添加一个 "clicked effect",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24221893/

相关文章:

安卓文字转图片

css - 如何添加一些CSS/html5效果让它有火热的错觉?

android - 未解析的类名 proguard-rules Android Studio 4.0

android - 动态改变 ImageView 的图像

android - 为什么我的 Android GridView 周围有多余的像素?

ios - 如何在 XCode 中折叠 View Controller 的边缘

java - 如何将Recyclerview的OnClickListener放到Activity中

java - 如何仅在选中时在 ViewPager 中加载 fragment

android - robotium 支持双点触控吗?