Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
leochuan committed Apr 11, 2017
1 parent c58c495 commit 73ce45a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All you need to concern about is which the property you want to change and how i
## Usage
#### Gradle
```Java
compile 'rouchuan.customlayoutmanager:customlayoutmanager:1.0.2'
compile 'rouchuan.customlayoutmanager:customlayoutmanager:1.0.3'
```
#### Default Properties
```Java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ protected void setUp() {

@Override
protected float maxRemoveOffset() {
return 60;
return 90;
}

@Override
protected float minRemoveOffset() {
return -60;
return -90;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
determinLayoutManager();
determineLayoutManager();
}
});
FloatingActionButton floatingActionButton2 = (FloatingActionButton) findViewById(R.id.fab2);
Expand All @@ -53,11 +53,11 @@ private void configureRecyclerView() {
scrollZoomLayoutManager = new ScrollZoomLayoutManager(this, Dp2px(10));
galleryLayoutManager = new GalleryLayoutManager(this, Dp2px(10));
recyclerView.addOnScrollListener(new CenterScrollListener());
determinLayoutManager();
determineLayoutManager();
recyclerView.setAdapter(new Adapter());
}

private void determinLayoutManager() {
private void determineLayoutManager() {
mode++;
if (mode == 4) mode = 0;
switch (mode) {
Expand Down
2 changes: 1 addition & 1 deletion customlayoutmanager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "1.0.2"
version = "1.0.3"

android {
compileSdkVersion 23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

public abstract class CustomLayoutManager extends RecyclerView.LayoutManager {

//Flags of scroll dirction
private static int SCROLL_LEFT = 1;
private static int SCROLL_RIGHT = 2;

private static int MAX_DISPLAY_ITEM_COUNT = 50;

protected Context context;
Expand Down Expand Up @@ -54,6 +50,7 @@ public CustomLayoutManager(Context context) {
public CustomLayoutManager(Context context, boolean shouldReverseLayout) {
this.context = context;
this.mShouldReverseLayout = shouldReverseLayout;
interval = setInterval();
}

@Override
Expand All @@ -72,7 +69,6 @@ public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State
mDecoratedChildHeight = getDecoratedMeasuredHeight(scrap);
startLeft = (getHorizontalSpace() - mDecoratedChildWidth) / 2;
startTop = (getVerticalSpace() - mDecoratedChildHeight) / 2;
interval = setInterval();
setUp();
detachAndScrapView(scrap, recycler);
}
Expand Down Expand Up @@ -186,21 +182,13 @@ public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, Recycler
layoutScrap(scrap, delta);
}

//different direction child will overlap different way
if (dx < 0)
layoutItems(recycler, state, SCROLL_LEFT);
else
layoutItems(recycler, state, SCROLL_RIGHT);
return willScroll;
}
layoutItems(recycler, state);

private void layoutItems(RecyclerView.Recycler recycler, RecyclerView.State state) {
int layoutDire = mShouldReverseLayout ? SCROLL_RIGHT : SCROLL_LEFT;
layoutItems(recycler, state, layoutDire);
return willScroll;
}

private void layoutItems(RecyclerView.Recycler recycler,
RecyclerView.State state, int oritention) {
RecyclerView.State state) {
if (state.isPreLayout()) return;

//remove the views which out of range
Expand All @@ -217,15 +205,13 @@ private void layoutItems(RecyclerView.Recycler recycler,
int end = getCurrentPosition() + MAX_DISPLAY_ITEM_COUNT / 2;
if (begin < 0) begin = 0;
if (end > getItemCount()) end = getItemCount();

for (int i = begin; i < end; i++) {
if (!removeCondition(getProperty(i) - offset)) {
if (findViewByPosition(i) == null) {
View scrap = recycler.getViewForPosition(i);
measureChildWithMargins(scrap, 0, 0);
if (oritention == SCROLL_LEFT)
addView(scrap, 0);
else
addView(scrap);
addView(scrap);
resetViewProperty(scrap);
float targetOffset = getProperty(i) - offset;
layoutScrap(scrap, targetOffset);
Expand Down

0 comments on commit 73ce45a

Please sign in to comment.