gpt4 book ai didi

安卓工作室 : ImageButton image/background flash

转载 作者:可可西里 更新时间:2023-11-01 11:42:56 25 4
gpt4 key购买 nike

请告诉我,是否有一种简单的方法可以在 Android 中闪烁/切换 ImageButton 的背景或图像?

我主要是试图让用户直观地知道何时在 ImageButton 上执行点击操作。所以闪烁按钮会有所帮助。

我已尝试研究该主题,但没有得出任何结论。唯一想到的是实现一个带有 HandlerTimer 以在两个可绘制 Assets 之间切换。但这似乎太过分了!

感谢你们在这个 Android 新手上放轻松。

最佳答案

我建议您使用 animation-list 作为 ImageButton 的背景。

1) 创建一个 flash_background.xml 文件:

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">

<item android:drawable="@drawable/first_background" android:duration="200" />
<item android:drawable="@drawable/second_background" android:duration="200" />

</animation-list>

2) 然后从代码

yourButton.setBackgroundResource(R.drawable.flash_background);
AnimationDrawable anim = (AnimationDrawable) yourButton.getBackground();
anim.start();

注意事项:

  • 您可以使用 android:duration 来加速/减速动画。

关于安卓工作室 : ImageButton image/background flash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35468903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com