成品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实现自动滚动效果实现的相关代码, 更多内容欢迎关注之后的文章
更多推荐
成品app直播源码,RecyclerView实现自动滚动效果
发布评论