垂直滚动TextView

【传送门】 https://www.jianshu.com/p/0c798a7b9727
【核心代码】

/**
 * @Author Lee
 * @Time 2018/3/7
 * @Theme 垂直滚动TextView
 */

public class AutoScrollTextActivity extends AppCompatActivity
    implements AutoVerticalScrollTextViewUtil.OnMyClickListener {

private ArrayList<CharSequence> list;
private AutoVerticalScrollTextViewUtil aUtil;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activit_auto_scroll_text);
    initView();
}


private void initView() {

    AutoVerticalScrollTextView textView = findViewById(R.id.autoVerticalScrollTextView);

    list = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        if (i % 2 == 0) {
            list.add(Html.fromHtml("<font color='#FF7198'>" + "测试垂直滚动" + "</font>" + i ));
        } else {
            list.add("测试垂直滚动" + i);
        }
    }

    // 初始化
    aUtil = new AutoVerticalScrollTextViewUtil(textView, list);
    aUtil.setDuration(2000)// 设置上下滚动事件间隔
            .start();
    // 点击事件监听
    aUtil.setOnMyClickListener(this);


}


@Override
public void onMyClickListener(int position, CharSequence title) {

    Toast.makeText(this, list.get(position) + " --- " + title, Toast.LENGTH_SHORT).show();
    if (aUtil.getIsRunning())
        // 停止滚动
        aUtil.stop();
    else
        // 开启滚动
        aUtil.start();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    aUtil.stop();
}
 }
    原文作者:zhengLH
    原文地址: https://www.jianshu.com/p/9bab9fbae484
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞