Skip to content

Commit

Permalink
Merge pull request #11 from Van1996/master
Browse files Browse the repository at this point in the history
修复两个问题
  • Loading branch information
loonggg authored Sep 29, 2018
2 parents fad1ac7 + 891fdea commit 5ecd11b
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,14 @@ public RecyclerViewBanner(Context context, AttributeSet attrs, int defStyleAttr)
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
int first = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
int last = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
if (first == last && currentIndex != last) {
currentIndex = last;
if (isShowIndicator && isTouched) {
isTouched = false;
switchIndicator();
}
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int next = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastVisibleItemPosition();
if (next != currentIndex) {
currentIndex = next;
if (isShowIndicator && isTouched) {
isTouched = false;
switchIndicator();
}
}
}
Expand Down Expand Up @@ -223,8 +220,9 @@ public void setRvBannerData(List data) {
mData.addAll(data);
}
if (mData.size() > 1) {
currentIndex = mData.size();
adapter.notifyDataSetChanged();
currentIndex = Integer.MAX_VALUE / 2 - (Integer.MAX_VALUE / 2) % mData.size();
// 将起始点设为最靠近的 MAX_VALUE/2 的,且为mData.size()整数倍的位置
mRecyclerView.scrollToPosition(currentIndex);
if (isShowIndicator) {
createIndicators();
Expand Down Expand Up @@ -287,6 +285,8 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
setPlaying(true);
}
break;
default:
break;
}
return super.dispatchTouchEvent(ev);
}
Expand Down

0 comments on commit 5ecd11b

Please sign in to comment.