Android渐变纠错效果

package com.example.myapplication4;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.View;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.widget.Button;import android.widget.TextView;import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity;public class SkipWordActivityOne extends AppCompatActivity {    TextView mAsrTextView1;    TextView mAsrTextView2;    Button startBtn;    int count = 0;    String last;    String current;    boolean isFinish;    int duration = 150;    private Handler mHandler = new Handler() {        @Override        public void handleMessage(Message msg) {            super.handleMessage(msg);            if (msg.what == 0) {                if (count < strings1.length - 1) {                    isFinish = false;                    last = strings1[count];                    current = strings1[count + 1];                    mAsrTextView1.setText(last);                    mAsrTextView2.setText(current);                    startAnimation(1, 0, mAsrTextView1);                    startAnimation(0, 1, mAsrTextView2);                    count++;                    if(count == strings1.length - 1){                        isFinish = true;                    }                    mHandler.sendEmptyMessageDelayed(0, duration);                } else {                    isFinish = true;                }            }        }    };    private String[] strings1 = new String[]{"甚至", "设置八点", "设置八点脑中", "设置八点闹钟"};    private String[] strings2 = new String[]{"今天", "今天的", "今天的天气", "今天的天气,今天的天气"};    private String[] strings3 = new String[]{"你好,我在听...", "打开设置", "打开音乐,打开音乐"};    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_skip_word_one);        mAsrTextView1 = findViewById(R.id.asr_textView1);        mAsrTextView2 = findViewById(R.id.asr_textView2);        startBtn = findViewById(R.id.start_btn);        mHandler.sendEmptyMessageDelayed(0, duration);        startBtn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                count = 0;                mAsrTextView1.setText("");                mAsrTextView2.setText("");                mHandler.sendEmptyMessageDelayed(0, duration);            }        });    }    private void startAnimation(int start, int end, View view) {        AlphaAnimation alphaAnimation = new AlphaAnimation(start, end);        alphaAnimation.setDuration(500);        view.startAnimation(alphaAnimation);        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {            @Override            public void onAnimationStart(Animation animation) {            }            @Override            public void onAnimationEnd(Animation animation) {                if (isFinish) {                    mAsrTextView1.setText(current);                }            }            @Override            public void onAnimationRepeat(Animation animation) {            }        });    }}

更多相关文章

  1. Android(安卓)全屏
  2. 图片走廊
  3. android设置背景半透明效果
  4. Android(安卓)WebView相关属性
  5. Mac版Android(安卓)studio中使用lambda表达式设置jdk版本问题
  6. Eclipse下android相关设置
  7. android全屏设置代码
  8. android圆形进度条ProgressBar颜色设置
  9. Android修改user版本默认关闭开发者选项模式,eng版本默认打开开

随机推荐

  1. Android(安卓)uses-feature
  2. android典型代码系列(二十八)------通话
  3. Android(安卓)SDK 有bug
  4. [Android(安卓)Samples视频系列之ApiDemo
  5. Android-Skillful-Craftsman(Android能工
  6. Android(安卓)判断Intent是否存在
  7. Android中文API(140) —— DexFile
  8. Android中打开新的Activity的三种方法
  9. android SDK 环境变量的设置
  10. 在android上使用ASCII显示特殊符号