admin管理员组文章数量:1794759
成品app直播源码,RecyclerView实现自动滚动效果
成品app直播源码,RecyclerView实现自动滚动效果实现的相关代码
public class PzAutoPageScrollRecyclerView extends RecyclerView implements Runnable { private String TAG = "PzAutoPageScrollRecyclerView"; private int itemPageCount; private int itemAllCount; private int scrollTime; private int nowPage = 0; private HandlerThread mHandlerThread = new HandlerThread("PzAutoPageScrollRecyclerView"); private Handler mHandler; public PzAutoPageScrollRecyclerView(@NonNull Context context) { super(context); } public PzAutoPageScrollRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public PzAutoPageScrollRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public void init(int itemPageCount, int itemAllCount, int scrollTime) { this.itemPageCount = itemPageCount; this.itemAllCount = itemAllCount; this.scrollTime = scrollTime; mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); } public void starAuto(int scrollTime) { this.scrollTime = scrollTime; mHandler.postDelayed(this, scrollTime); } void stopAuto() { removeCallbacks(this); } void last() { if ((nowPage - 1) >= 0) { nowPage--; smoothScrollToPosition(nowPage * itemPageCount); } } void next() { if ((nowPage + 1) * itemPageCount < itemAllCount) { nowPage++; smoothScrollToPosition(nowPage * itemPageCount); } } @Override public void run() { if (itemPageCount < itemAllCount) { if ((nowPage + 1) * itemPageCount < itemAllCount) { nowPage++; smoothScrollToPosition(nowPage * itemPageCount); } else { nowPage = 1; smoothScrollToPosition(nowPage * itemPageCount); nowPage = 0; smoothScrollToPosition(nowPage * itemPageCount); } } else { mHandler.postDelayed(this, scrollTime); } } @Override public void onScrollStateChanged(int state) { super.onScrollStateChanged(state); if (getScrollState() == 0) { mHandler.postDelayed(this, scrollTime); } } public int getItemAllCount() { return itemAllCount; } public void setItemAllCount(int itemAllCount) { this.itemAllCount = itemAllCount; } public int getItemPageCount() { return itemPageCount; } public void setItemPageCount(int itemPageCount) { this.itemPageCount = itemPageCount; } public int getScrollTime() { return scrollTime; } public void setScrollTime(int scrollTime) { this.scrollTime = scrollTime; } }以上就是成品app直播源码,RecyclerView实现自动滚动效果实现的相关代码, 更多内容欢迎关注之后的文章
本文标签: 成品源码效果appRecyclerView
版权声明:本文标题:成品app直播源码,RecyclerView实现自动滚动效果 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686525524a77742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论