Skip to content

Commit

Permalink
fix notifydatasetchange display error
Browse files Browse the repository at this point in the history
(cherry picked from commit 10eeb5d)
  • Loading branch information
kHRYSTAL committed Nov 18, 2017
1 parent 606981a commit f22353d
Showing 1 changed file with 27 additions and 0 deletions.
Expand Up @@ -8,6 +8,8 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;

Expand All @@ -25,6 +27,8 @@
*/
public class CircleRecyclerView extends RecyclerView implements View.OnClickListener {

private static final String TAG = "CircleRecyclerView";

private static final int DEFAULT_SELECTION = Integer.MAX_VALUE >> 1;

private boolean mIsForceCentering;
Expand Down Expand Up @@ -83,6 +87,9 @@ else if (layoutManager.canScrollVertically())
setClipChildren(false);
mCurrentCenterChildView = findViewAtCenter();
smoothScrollToView(mCurrentCenterChildView);
} else {
setClipToPadding(false);
setClipChildren(false);
}

if (mCurrentCenterChildView != null)
Expand Down Expand Up @@ -114,6 +121,26 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
mOnScrollListener.onScrollChanged(l, t, oldl, oldt);
}

@Override
public void requestLayout() {
super.requestLayout();

if (mViewMode != null && getLayoutManager() != null) {
int count = getLayoutManager().getChildCount();
for (int i = 0; i < count; ++i) {
View v = getChildAt(i);
if (v != mCurrentCenterChildView && mCenterItemClickListener != null)
v.setOnClickListener(null);
if (v == mCurrentCenterChildView)
v.setTag(R.string.tag_is_center, true);
else
v.setTag(R.string.tag_is_center, false);
mViewMode.applyToView(v, this);
}
}

}

public void smoothScrollToView(View v) {
int distance = 0;
if (getLayoutManager() instanceof LinearLayoutManager) {
Expand Down

0 comments on commit f22353d

Please sign in to comment.