当前位置:   article > 正文

Android代码实现控件闪烁效果_android 边缘闪烁 怎么实现

android 边缘闪烁 怎么实现

在项目开发过程中,我们有时会遇到需要控件闪烁和停止的问题。

MainActivity里的代码:

两个BUTTON一个TEXT

start=findViewById(R.id.button_start);
stop=findViewById(R.id.button_stop);
textdebug=findViewById(R.id.text_debug);
start.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        startFlick(textdebug);
    }
});
stop.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        stopFlick(textdebug);
    }
});

xml文件:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button_start"
    android:text="开始"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button_stop"
    android:text="停止"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/text_debug"
    android:text="控件闪烁测试"
    android:textSize="22dp"
    android:gravity="center"
    android:background="@color/red"
    android:textColor="@color/black"/>
/**开启View闪烁效果**/
public 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闪烁效果**/
public void stopFlick( View view ) {
    if (null == view) {
        return;
    }
    view.clearAnimation();
}

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/287618
推荐阅读
相关标签
  

闽ICP备14008679号