您的位置:首页 > 编程语言

开启和关闭按钮闪烁效果代码

2017-12-15 14:50 225 查看
   在Android系统中,系统按钮没有控制闪烁的方法,我们可借用AlphaAnimation来自己实现,对于有些需要提示用户点击的地方,闪烁按钮是一个不错的方法。
一、开启和关闭按钮闪烁效果代码如下:

     /**

     * 开启View闪烁效果

     * 

     * */

    private void startFlick( View view ){

        if( null == view ){

            return;

        }

        Animation alphaAnimation = new AlphaAnimation( 1, 0 );

        alphaAnimation.setDuration( 300 );

        alphaAnimation.setInterpolator( new LinearInterpolator( ) );

        alphaAnimation.setRepeatCount( Animation.INFINITE );

        alphaAnimation.setRepeatMode( Animation.REVERSE );

        view.startAnimation( alphaAnimation );

    }

    /**

     * 取消View闪烁效果

     * 

     * */

    private void stopFlick( View view ){

        if( null == view ){

            return;

        }

        view.clearAnimation( );

    }

二、为需要使用该效果的视图添加闪烁效果:

startFlick( startBtn );

在响应按钮点击事件的地方停止闪烁效果:

stopFlick( startBtn );
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: