mirror of
https://github.com/alibaba/vlayout.git
synced 2026-10-17 05:07:37 +08:00
fix space computing error between stickyLayoutHelper and rangeGridLayoutHelper
This commit is contained in:
@@ -152,7 +152,7 @@ public class VLayoutActivity extends Activity {
|
||||
}
|
||||
});
|
||||
|
||||
//layoutManager.setRecycleOffset(300);
|
||||
layoutManager.setRecycleOffset(300);
|
||||
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
|
||||
@@ -591,7 +591,7 @@ public abstract class BaseLayoutHelper extends MarginLayoutHelper {
|
||||
? (isLayoutEnd ? calGap(lastMarginLayoutHelper.mMarginBottom, mMarginTop) : calGap(lastMarginLayoutHelper.mMarginTop, mMarginBottom))
|
||||
: (isLayoutEnd ? calGap(lastMarginLayoutHelper.mMarginRight, mMarginLeft) : calGap(lastMarginLayoutHelper.mMarginLeft, mMarginRight));
|
||||
}
|
||||
Log.e("huang", "computeStartSpace offset: " + offset + ", isLayoutEnd: " + isLayoutEnd + ", " + this);
|
||||
//Log.e("huang", "computeStartSpace offset: " + offset + ", isLayoutEnd: " + isLayoutEnd + ", " + this);
|
||||
startSpace += layoutInVertical
|
||||
? (isLayoutEnd ? mPaddingTop : mPaddingBottom)
|
||||
: (isLayoutEnd ? mPaddingLeft : mPaddingRight);
|
||||
@@ -605,8 +605,8 @@ public abstract class BaseLayoutHelper extends MarginLayoutHelper {
|
||||
int endSpace = layoutInVertical
|
||||
? (isLayoutEnd ? mMarginBottom + mPaddingBottom : mMarginTop + mPaddingTop)
|
||||
: (isLayoutEnd ? mMarginRight + mPaddingRight : mMarginLeft + mPaddingLeft);
|
||||
Log.e("huang", "computeEndSpace offset: " + endSpace + ", isLayoutEnd: " + isLayoutEnd + ", " + this);
|
||||
Log.e("huang", "===================\n\n");
|
||||
//Log.e("huang", "computeEndSpace offset: " + endSpace + ", isLayoutEnd: " + isLayoutEnd + ", " + this);
|
||||
//Log.e("huang", "===================\n\n");
|
||||
return endSpace;
|
||||
}
|
||||
|
||||
|
||||
@@ -275,6 +275,10 @@ public class OnePlusNLayoutHelper extends AbstractFullFillLayoutHelper {
|
||||
if (offset == 1 && isLayoutEnd) {
|
||||
return 0;
|
||||
}
|
||||
} else if (getItemCount() == 5) {
|
||||
if (offset == 1 && isLayoutEnd) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (helper.getOrientation() == VERTICAL) {
|
||||
|
||||
@@ -843,6 +843,26 @@ public class RangeGridLayoutHelper extends BaseLayoutHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public int getBorderStartSpace(LayoutManagerHelper helper) {
|
||||
int start = getRange().getLower().intValue();
|
||||
RangeStyle rangeStyle = mRangeStyle.findRangeStyleByPosition(start);
|
||||
if (helper.getOrientation() == VERTICAL) {
|
||||
return rangeStyle.getFamilyMarginTop() + rangeStyle.getFamilyPaddingTop();
|
||||
} else {
|
||||
return rangeStyle.getFamilyMarginLeft() + rangeStyle.getFamilyPaddingLeft();
|
||||
}
|
||||
}
|
||||
|
||||
public int getBorderEndSpace(LayoutManagerHelper helper) {
|
||||
int end = getRange().getUpper().intValue();
|
||||
RangeStyle rangeStyle = mRangeStyle.findRangeStyleByPosition(end);
|
||||
if (helper.getOrientation() == VERTICAL) {
|
||||
return rangeStyle.getFamilyMarginBottom() + rangeStyle.getFamilyPaddingBottom();
|
||||
} else {
|
||||
return rangeStyle.getFamilyMarginRight() + rangeStyle.getFamilyPaddingRight();
|
||||
}
|
||||
}
|
||||
|
||||
public static class GridRangeStyle extends RangeStyle<GridRangeStyle> {
|
||||
|
||||
private float mAspectRatio = Float.NaN;
|
||||
|
||||
@@ -93,7 +93,7 @@ public class RangeStyle<T extends RangeStyle> {
|
||||
}
|
||||
|
||||
/**
|
||||
* set paddings for this layoutHelper
|
||||
* set paddings for this style
|
||||
* @param leftPadding left padding
|
||||
* @param topPadding top padding
|
||||
* @param rightPadding right padding
|
||||
@@ -107,7 +107,7 @@ public class RangeStyle<T extends RangeStyle> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set margins for this layoutHelper
|
||||
* Set margins for this style
|
||||
*
|
||||
* @param leftMargin left margin
|
||||
* @param topMargin top margin
|
||||
@@ -219,18 +219,34 @@ public class RangeStyle<T extends RangeStyle> {
|
||||
mMarginBottom = marginBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total horizontal margin include its ancestor's and itself's.
|
||||
* @return
|
||||
*/
|
||||
public int getFamilyHorizontalMargin() {
|
||||
return (mParent != null ? mParent.getFamilyHorizontalMargin() : 0) + getHorizontalMargin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total vertical margin include its ancestor's and itself's.
|
||||
* @return
|
||||
*/
|
||||
public int getFamilyVerticalMargin() {
|
||||
return (mParent != null ? mParent.getFamilyVerticalMargin() : 0) + getVerticalMargin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total horizontal padding include its ancestor's and itself's.
|
||||
* @return
|
||||
*/
|
||||
public int getFamilyHorizontalPadding() {
|
||||
return (mParent != null ? mParent.getFamilyHorizontalPadding() : 0) + getHorizontalPadding();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total vertical padding include its ancestor's and itself's.
|
||||
* @return
|
||||
*/
|
||||
public int getFamilyVerticalPadding() {
|
||||
return (mParent != null ? mParent.getFamilyVerticalPadding() : 0) + getVerticalPadding();
|
||||
}
|
||||
@@ -267,18 +283,34 @@ public class RangeStyle<T extends RangeStyle> {
|
||||
return (mParent != null ? mParent.getFamilyMarginBottom() : 0) + mMarginBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total horizontal margin of its ancestor's.
|
||||
* @return
|
||||
*/
|
||||
public int getAncestorHorizontalMargin() {
|
||||
return (mParent != null ? mParent.getAncestorHorizontalMargin() + mParent.getHorizontalMargin() : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total vertical margin of its ancestor's.
|
||||
* @return
|
||||
*/
|
||||
public int getAncestorVerticalMargin() {
|
||||
return (mParent != null ? mParent.getAncestorVerticalMargin() + mParent.getVerticalMargin(): 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total horizontal padding of its ancestor's.
|
||||
* @return
|
||||
*/
|
||||
public int getAncestorHorizontalPadding() {
|
||||
return (mParent != null ? mParent.getAncestorHorizontalPadding() + mParent.getHorizontalPadding() : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total vertical padding of its ancestor's.
|
||||
* @return
|
||||
*/
|
||||
public int getAncestorVerticalPadding() {
|
||||
return (mParent != null ? mParent.getAncestorVerticalPadding() + mParent.getVerticalPadding() : 0);
|
||||
}
|
||||
|
||||
@@ -24,18 +24,17 @@
|
||||
|
||||
package com.alibaba.android.vlayout.layout;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.OrientationHelper;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.alibaba.android.vlayout.LayoutHelper;
|
||||
import com.alibaba.android.vlayout.LayoutManagerHelper;
|
||||
import com.alibaba.android.vlayout.OrientationHelperEx;
|
||||
import com.alibaba.android.vlayout.VirtualLayoutManager;
|
||||
import com.alibaba.android.vlayout.VirtualLayoutManager.LayoutStateWrapper;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import static android.support.v7.widget.LinearLayoutManager.VERTICAL;
|
||||
|
||||
|
||||
@@ -308,8 +307,10 @@ public class StickyLayoutHelper extends FixAreaLayoutHelper {
|
||||
if (anchorPos < mPos) { // TODO: when view size is larger than totalSpace!
|
||||
top = orientationHelper.getDecoratedEnd(refer);
|
||||
LayoutHelper layoutHelper = helper.findLayoutHelperByPosition(anchorPos);
|
||||
if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
top = top + ((MarginLayoutHelper) layoutHelper).mMarginBottom + ((MarginLayoutHelper) layoutHelper).mPaddingBottom;
|
||||
if (layoutHelper instanceof RangeGridLayoutHelper) {
|
||||
top = top + ((RangeGridLayoutHelper) layoutHelper).getBorderEndSpace(helper);
|
||||
} else if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
top = top + ((MarginLayoutHelper) layoutHelper).getMarginBottom() + ((MarginLayoutHelper) layoutHelper).getPaddingBottom();
|
||||
}
|
||||
if (top >= mOffset + mAdjuster.top) {
|
||||
mDoNormalHandle = true;
|
||||
@@ -327,8 +328,10 @@ public class StickyLayoutHelper extends FixAreaLayoutHelper {
|
||||
if (anchorPos > mPos) {
|
||||
bottom = orientationHelper.getDecoratedStart(refer);
|
||||
LayoutHelper layoutHelper = helper.findLayoutHelperByPosition(anchorPos);
|
||||
if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
bottom = bottom - ((MarginLayoutHelper) layoutHelper).mMarginTop - ((MarginLayoutHelper) layoutHelper).mPaddingTop;
|
||||
if (layoutHelper instanceof RangeGridLayoutHelper) {
|
||||
bottom = bottom - ((RangeGridLayoutHelper) layoutHelper).getBorderStartSpace(helper);
|
||||
} else if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
bottom = bottom - ((MarginLayoutHelper) layoutHelper).getMarginTop() - ((MarginLayoutHelper) layoutHelper).getPaddingTop();
|
||||
}
|
||||
if (bottom >= mOffset + mAdjuster.bottom) {
|
||||
mDoNormalHandle = true;
|
||||
@@ -364,34 +367,40 @@ public class StickyLayoutHelper extends FixAreaLayoutHelper {
|
||||
|
||||
View refer = null;
|
||||
if (mStickyStart) {
|
||||
for (int i = 0; i < helper.getChildCount(); i++) {
|
||||
refer = helper.getChildAt(i);
|
||||
int anchorPos = helper.getPosition(refer);
|
||||
if (anchorPos > mPos) { // TODO: when view size is larger than totalSpace!
|
||||
bottom = orientationHelper.getDecoratedStart(refer);
|
||||
LayoutHelper layoutHelper = helper.findLayoutHelperByPosition(anchorPos);
|
||||
if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
bottom = bottom - ((MarginLayoutHelper) layoutHelper).mMarginTop - ((MarginLayoutHelper) layoutHelper).mPaddingTop;
|
||||
}
|
||||
top = bottom - consumed;
|
||||
index = i + 1;
|
||||
mDoNormalHandle = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = helper.getChildCount() - 1; i >= 0; i--) {
|
||||
refer = helper.getChildAt(i);
|
||||
int anchorPos = helper.getPosition(refer);
|
||||
if (anchorPos < mPos) {
|
||||
top = orientationHelper.getDecoratedEnd(refer);
|
||||
LayoutHelper layoutHelper = helper.findLayoutHelperByPosition(anchorPos);
|
||||
if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
top = top + ((MarginLayoutHelper) layoutHelper).mMarginBottom + ((MarginLayoutHelper) layoutHelper).mPaddingBottom;
|
||||
if (layoutHelper instanceof RangeGridLayoutHelper) {
|
||||
top = top + ((RangeGridLayoutHelper) layoutHelper).getBorderEndSpace(helper);
|
||||
} else if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
top = top + ((MarginLayoutHelper) layoutHelper).getMarginBottom() + ((MarginLayoutHelper) layoutHelper).getPaddingBottom();
|
||||
}
|
||||
bottom = top + consumed;
|
||||
index = i;
|
||||
mDoNormalHandle = true;
|
||||
Log.d("Longer", "compute bottom top " + bottom + " " + top);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
for (int i = 0; i < helper.getChildCount(); i++) {
|
||||
refer = helper.getChildAt(i);
|
||||
int anchorPos = helper.getPosition(refer);
|
||||
if (anchorPos > mPos) { // TODO: when view size is larger than totalSpace!
|
||||
bottom = orientationHelper.getDecoratedStart(refer);
|
||||
LayoutHelper layoutHelper = helper.findLayoutHelperByPosition(anchorPos);
|
||||
if (layoutHelper instanceof RangeGridLayoutHelper) {
|
||||
bottom = bottom - ((RangeGridLayoutHelper) layoutHelper).getBorderStartSpace(helper);
|
||||
} else if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
bottom = bottom - ((MarginLayoutHelper) layoutHelper).getMarginTop() - ((MarginLayoutHelper) layoutHelper).getPaddingTop();
|
||||
}
|
||||
top = bottom - consumed;
|
||||
index = i + 1;
|
||||
mDoNormalHandle = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -555,8 +564,10 @@ public class StickyLayoutHelper extends FixAreaLayoutHelper {
|
||||
if (anchorPos < mPos) { // TODO: when view size is larger than totalSpace!
|
||||
top = orientationHelper.getDecoratedEnd(refer);
|
||||
LayoutHelper layoutHelper = helper.findLayoutHelperByPosition(anchorPos);
|
||||
if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
top = top + ((MarginLayoutHelper) layoutHelper).mMarginBottom + ((MarginLayoutHelper) layoutHelper).mPaddingBottom;
|
||||
if (layoutHelper instanceof RangeGridLayoutHelper) {
|
||||
top = top + ((RangeGridLayoutHelper) layoutHelper).getBorderEndSpace(helper);
|
||||
} else if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
top = top + ((MarginLayoutHelper) layoutHelper).getMarginBottom() + ((MarginLayoutHelper) layoutHelper).getPaddingBottom();
|
||||
}
|
||||
bottom = top + consumed;
|
||||
index = i + 1;
|
||||
@@ -570,8 +581,10 @@ public class StickyLayoutHelper extends FixAreaLayoutHelper {
|
||||
if (anchorPos > mPos) {
|
||||
bottom = orientationHelper.getDecoratedStart(refer);
|
||||
LayoutHelper layoutHelper = helper.findLayoutHelperByPosition(anchorPos);
|
||||
if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
bottom = bottom - ((MarginLayoutHelper) layoutHelper).mMarginTop - ((MarginLayoutHelper) layoutHelper).mPaddingTop;
|
||||
if (layoutHelper instanceof RangeGridLayoutHelper) {
|
||||
bottom = bottom - ((RangeGridLayoutHelper) layoutHelper).getBorderStartSpace(helper);
|
||||
} else if (layoutHelper instanceof MarginLayoutHelper) {
|
||||
bottom = bottom - ((MarginLayoutHelper) layoutHelper).getMarginTop() - ((MarginLayoutHelper) layoutHelper).getPaddingTop();
|
||||
}
|
||||
top = bottom - consumed;
|
||||
index = i;
|
||||
|
||||
Reference in New Issue
Block a user