有篇文章是listview 利用handler自动滚动到底部在从头开始循环滚动:
http://blog.csdn.net/qq_34900897/article/details/78732099
在魅族有问题,滑动到底部就无法跳到顶部:
以下用recyclerview实现就没有存在这些问题:
public class MainActivity extends AppCompatActivity {private RecyclerView list_v;private BaseRecyclerAdapter<String> adapter;private List<String> data = new ArrayList<>();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);list_v = findViewById(R.id.list_v);list_v.setLayoutManager(new GridLayoutManager(this, 1));list_v.setAdapter(adapter = new BaseRecyclerAdapter<String>(this, R.layout.test_item, data) {@Overridepublic void bindData(SuperHolder holder, int position, String bean) {TextView tv = holder.getView(R.id.mass_tv);tv.setText(bean);}});for (int i = 0; i < 10; i++) {data.add("position: " + i);}adapter.notifyDataSetChanged();}private Timer t;public void click(View view) {switch (view.getId()) {case R.id.btn_go:if (t != null) {t.cancel();}t = new Timer();t.schedule(new TimerTask() {@Overridepublic void run() {runOnUiThread(new Runnable() {@Overridepublic void run() {if (isSlideToBottom(list_v)) {list_v.scrollToPosition(0);return;}list_v.smoothScrollBy(0, dpToPx(50), new LinearInterpolator());}});}}, 500, 1000);break;case R.id.btn_stop:if (t != null)t.cancel();break;}}@Overrideprotected void onDestroy() {super.onDestroy();
if (t != null)t.cancel();
}
public static boolean isSlideToBottom(RecyclerView recyclerView) {if (recyclerView == null) return false;if (recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange())return true;return false;}