feat:Scroller's childnode can match parent on Android

This commit is contained in:
pengfei.zhou 2019-11-20 15:05:21 +08:00
parent 7d6ad70682
commit b9382a4659

View File

@ -135,12 +135,6 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
*/ */
private VelocityTracker mVelocityTracker; private VelocityTracker mVelocityTracker;
/**
* When set to true, the scroll view measure its child to make it fill the currently
* visible area.
*/
private boolean mFillViewport;
/** /**
* Whether arrow scrolling is animated. * Whether arrow scrolling is animated.
*/ */
@ -203,9 +197,6 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
final TypedArray a = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(
attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0); attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0);
setFillViewport(a.getBoolean(0, false));
a.recycle(); a.recycle();
mParentHelper = new NestedScrollingParentHelper(this); mParentHelper = new NestedScrollingParentHelper(this);
@ -513,30 +504,6 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
return false; return false;
} }
/**
* Indicates whether this ScrollView's content is stretched to fill the viewport.
*
* @return True if the content fills the viewport, false otherwise.
* @attr name android:fillViewport
*/
public boolean isFillViewport() {
return mFillViewport;
}
/**
* Set whether this ScrollView should stretch its content height to fill the viewport or not.
*
* @param fillViewport True to stretch the content's height to the viewport's
* boundaries, false otherwise.
* @attr name android:fillViewport
*/
public void setFillViewport(boolean fillViewport) {
if (fillViewport != mFillViewport) {
mFillViewport = fillViewport;
requestLayout();
}
}
/** /**
* @return Whether arrow scrolling will animate its transition. * @return Whether arrow scrolling will animate its transition.
*/ */
@ -566,10 +533,6 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (!mFillViewport) {
return;
}
final int widthMode = MeasureSpec.getMode(widthMeasureSpec); final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int heightMode = MeasureSpec.getMode(heightMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (heightMode == MeasureSpec.UNSPECIFIED && widthMode == MeasureSpec.UNSPECIFIED) { if (heightMode == MeasureSpec.UNSPECIFIED && widthMode == MeasureSpec.UNSPECIFIED) {
@ -587,14 +550,17 @@ public class HVScrollView extends FrameLayout implements NestedScrollingParent,
int childWidthMeasureSpec; int childWidthMeasureSpec;
int childHeightMeasureSpec; int childHeightMeasureSpec;
final FrameLayout.LayoutParams lp = (LayoutParams) child.getLayoutParams(); final FrameLayout.LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (child.getMeasuredWidth() < width) { if (lp.width != ViewGroup.LayoutParams.MATCH_PARENT && lp.height != ViewGroup.LayoutParams.MATCH_PARENT) {
return;
}
if (child.getMeasuredWidth() < width && lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
} else { } else {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
getPaddingLeft() + getPaddingRight(), lp.width); getPaddingLeft() + getPaddingRight(), lp.width);
} }
if (child.getMeasuredHeight() < height) { if (child.getMeasuredHeight() < height && lp.height == ViewGroup.LayoutParams.MATCH_PARENT) {
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
} else { } else {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);