机器人 - 我怎样才能使一个按钮闪光? [英] android - How can I make a button flash?

查看:104
本文介绍了机器人 - 我怎样才能使一个按钮闪光?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法,在code,使不断按钮闪烁,然后停在pressed闪烁?

Is there any way, in code, to make a button flash continually and then stop flashing when pressed?

推荐答案

有几种,这取决于什么样的闪烁你的意思。 你可以,例如,使用奥飞动漫作为你的按钮首先出现启动它。当用户点击按钮,在你的 OnClickListener 只是做 clearAnimation()

There are several, depending on what kind of flashing you mean. You can, for example, use alpha animation and start it as your button first appears. And when the user clicks button, in your OnClickListener just do clearAnimation().

例如:

public void onCreate(Bundle savedInstanceState) {
    final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
    final Button btn = (Button) findViewById(R.id.your_btn);
    btn.startAnimation(animation);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            view.clearAnimation();
        }
    });
}

这篇关于机器人 - 我怎样才能使一个按钮闪光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆