mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Added percentage support for width, height and margin properties.
This commit is contained in:
@@ -18,7 +18,8 @@ public class AbsoluteLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
||||||
int measureWidth = 0;
|
int measureWidth = 0;
|
||||||
int measureHeight = 0;
|
int measureHeight = 0;
|
||||||
int childMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
int childMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
||||||
@@ -29,8 +30,7 @@ public class AbsoluteLayout extends LayoutBase {
|
|||||||
if (child.getVisibility() == View.GONE) {
|
if (child.getVisibility() == View.GONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
CommonLayoutParams.measureChild(child, childMeasureSpec, childMeasureSpec);
|
CommonLayoutParams.measureChild(child, childMeasureSpec, childMeasureSpec);
|
||||||
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
||||||
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
||||||
@@ -56,7 +56,6 @@ public class AbsoluteLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
|
||||||
int leftPadding = this.getPaddingLeft();
|
int leftPadding = this.getPaddingLeft();
|
||||||
int topPadding = this.getPaddingTop();
|
int topPadding = this.getPaddingTop();
|
||||||
int count = this.getChildCount();
|
int count = this.getChildCount();
|
||||||
@@ -78,5 +77,7 @@ public class AbsoluteLayout extends LayoutBase {
|
|||||||
|
|
||||||
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childBottom);
|
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommonLayoutParams.restoreOriginalParams(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.nativescript.widgets;
|
package org.nativescript.widgets;
|
||||||
|
|
||||||
@@ -11,52 +11,60 @@ import android.util.Log;
|
|||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.MeasureSpec;
|
import android.view.View.MeasureSpec;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hhristov
|
* @author hhristov
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CommonLayoutParams extends FrameLayout.LayoutParams {
|
public class CommonLayoutParams extends FrameLayout.LayoutParams {
|
||||||
|
|
||||||
static final String TAG = "NSLayout";
|
static final String TAG = "NSLayout";
|
||||||
static int debuggable = -1;
|
static int debuggable = -1;
|
||||||
private static final StringBuilder sb = new StringBuilder();
|
private static final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
public CommonLayoutParams() {
|
|
||||||
super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float widthPercent = 0;
|
public CommonLayoutParams() {
|
||||||
public float heightPercent = 0;
|
super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||||
|
}
|
||||||
public float topMarginPercent = 0;
|
|
||||||
public float leftMarginPercent = 0;
|
public float widthPercent = 0;
|
||||||
public float bottomMarginPercent = 0;
|
public float heightPercent = 0;
|
||||||
public float rightMarginPercent = 0;
|
|
||||||
|
public float topMarginPercent = 0;
|
||||||
public int left = 0;
|
public float leftMarginPercent = 0;
|
||||||
public int top = 0;
|
public float bottomMarginPercent = 0;
|
||||||
public int row = 0;
|
public float rightMarginPercent = 0;
|
||||||
public int column = 0;
|
|
||||||
public int rowSpan = 1;
|
public int widthOriginal = -1;
|
||||||
public int columnSpan = 1;
|
public int heightOriginal = -1;
|
||||||
public Dock dock = Dock.left;
|
|
||||||
|
public int topMarginOriginal = -1;
|
||||||
public static int getDesiredWidth(View view) {
|
public int leftMarginOriginal = -1;
|
||||||
CommonLayoutParams lp = (CommonLayoutParams)view.getLayoutParams();
|
public int bottomMarginOriginal = -1;
|
||||||
|
public int rightMarginOriginal = -1;
|
||||||
|
|
||||||
|
public int left = 0;
|
||||||
|
public int top = 0;
|
||||||
|
public int row = 0;
|
||||||
|
public int column = 0;
|
||||||
|
public int rowSpan = 1;
|
||||||
|
public int columnSpan = 1;
|
||||||
|
public Dock dock = Dock.left;
|
||||||
|
|
||||||
|
protected static int getDesiredWidth(View view) {
|
||||||
|
CommonLayoutParams lp = (CommonLayoutParams) view.getLayoutParams();
|
||||||
return view.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
|
return view.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDesiredHeight(View view) {
|
protected static int getDesiredHeight(View view) {
|
||||||
CommonLayoutParams lp = (CommonLayoutParams)view.getLayoutParams();
|
CommonLayoutParams lp = (CommonLayoutParams) view.getLayoutParams();
|
||||||
return view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
|
return view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use our own layout method because the one in FrameLayout is broken when margins are set and gravity is CENTER_VERTICAL or CENTER_HORIZONTAL.
|
// We use our own layout method because the one in FrameLayout is broken when margins are set and gravity is CENTER_VERTICAL or CENTER_HORIZONTAL.
|
||||||
@SuppressLint("RtlHardcoded")
|
@SuppressLint("RtlHardcoded")
|
||||||
public static void layoutChild(View child, int left, int top, int right, int bottom) {
|
protected static void layoutChild(View child, int left, int top, int right, int bottom) {
|
||||||
if (child.getVisibility() == View.GONE) {
|
if (child.getVisibility() == View.GONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -67,216 +75,287 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams {
|
|||||||
int childWidth = child.getMeasuredWidth();
|
int childWidth = child.getMeasuredWidth();
|
||||||
int childHeight = child.getMeasuredHeight();
|
int childHeight = child.getMeasuredHeight();
|
||||||
|
|
||||||
CommonLayoutParams lp = (CommonLayoutParams)child.getLayoutParams();
|
CommonLayoutParams lp = (CommonLayoutParams) child.getLayoutParams();
|
||||||
int gravity = lp.gravity;
|
int gravity = lp.gravity;
|
||||||
if (gravity == -1) {
|
if (gravity == -1) {
|
||||||
gravity = Gravity.FILL;
|
gravity = Gravity.FILL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
||||||
|
|
||||||
// If we have explicit height and gravity is FILL we need to be centered otherwise our explicit height won't be taken into account.
|
// If we have explicit height and gravity is FILL we need to be centered otherwise our explicit height won't be taken into account.
|
||||||
if (lp.height >= 0 && verticalGravity == Gravity.FILL_VERTICAL) {
|
if (lp.height >= 0 && verticalGravity == Gravity.FILL_VERTICAL) {
|
||||||
verticalGravity = Gravity.CENTER_VERTICAL;
|
verticalGravity = Gravity.CENTER_VERTICAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (verticalGravity) {
|
switch (verticalGravity) {
|
||||||
case Gravity.TOP:
|
case Gravity.TOP:
|
||||||
childTop = top + lp.topMargin;
|
childTop = top + lp.topMargin;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Gravity.CENTER_VERTICAL:
|
case Gravity.CENTER_VERTICAL:
|
||||||
childTop = top + (bottom - top - childHeight + lp.topMargin - lp.bottomMargin) / 2;
|
childTop = top + (bottom - top - childHeight + lp.topMargin - lp.bottomMargin) / 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Gravity.BOTTOM:
|
case Gravity.BOTTOM:
|
||||||
childTop = bottom - childHeight - lp.bottomMargin;
|
childTop = bottom - childHeight - lp.bottomMargin;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Gravity.FILL_VERTICAL:
|
case Gravity.FILL_VERTICAL:
|
||||||
default:
|
default:
|
||||||
childTop = top + lp.topMargin;
|
childTop = top + lp.topMargin;
|
||||||
childHeight = bottom - top - (lp.topMargin + lp.bottomMargin);
|
childHeight = bottom - top - (lp.topMargin + lp.bottomMargin);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int horizontalGravity = Gravity.getAbsoluteGravity(gravity, child.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
|
int horizontalGravity = Gravity.getAbsoluteGravity(gravity, child.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
|
||||||
|
|
||||||
// If we have explicit width and gravity is FILL we need to be centered otherwise our explicit width won't be taken into account.
|
// If we have explicit width and gravity is FILL we need to be centered otherwise our explicit width won't be taken into account.
|
||||||
if (lp.width >= 0 && horizontalGravity == Gravity.FILL_HORIZONTAL) {
|
if (lp.width >= 0 && horizontalGravity == Gravity.FILL_HORIZONTAL) {
|
||||||
horizontalGravity = Gravity.CENTER_HORIZONTAL;
|
horizontalGravity = Gravity.CENTER_HORIZONTAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (horizontalGravity) {
|
switch (horizontalGravity) {
|
||||||
case Gravity.LEFT:
|
case Gravity.LEFT:
|
||||||
childLeft = left + lp.leftMargin;
|
childLeft = left + lp.leftMargin;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Gravity.CENTER_HORIZONTAL:
|
case Gravity.CENTER_HORIZONTAL:
|
||||||
childLeft = left + (right - left - childWidth + lp.leftMargin - lp.rightMargin) / 2;
|
childLeft = left + (right - left - childWidth + lp.leftMargin - lp.rightMargin) / 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Gravity.RIGHT:
|
case Gravity.RIGHT:
|
||||||
childLeft = right - childWidth - lp.rightMargin;
|
childLeft = right - childWidth - lp.rightMargin;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Gravity.FILL_HORIZONTAL:
|
case Gravity.FILL_HORIZONTAL:
|
||||||
default:
|
default:
|
||||||
childLeft = left + lp.leftMargin;
|
childLeft = left + lp.leftMargin;
|
||||||
childWidth = right - left - (lp.leftMargin + lp.rightMargin);
|
childWidth = right - left - (lp.leftMargin + lp.rightMargin);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int childRight = Math.round(childLeft + childWidth);
|
int childRight = Math.round(childLeft + childWidth);
|
||||||
int childBottom = Math.round(childTop + childHeight);
|
int childBottom = Math.round(childTop + childHeight);
|
||||||
childLeft = Math.round(childLeft);
|
childLeft = Math.round(childLeft);
|
||||||
childTop = Math.round(childTop);
|
childTop = Math.round(childTop);
|
||||||
|
|
||||||
// Re-measure TextView because it is not centered if layout width is larger than measure width.
|
// Re-measure TextView because it is not centered if layout width is larger than measure width.
|
||||||
if (child instanceof android.widget.TextView) {
|
if (child instanceof android.widget.TextView) {
|
||||||
|
|
||||||
boolean canChangeWidth = lp.width < 0;
|
boolean canChangeWidth = lp.width < 0;
|
||||||
boolean canChangeHeight = lp.height < 0;
|
boolean canChangeHeight = lp.height < 0;
|
||||||
|
|
||||||
int measuredWidth = child.getMeasuredWidth();
|
int measuredWidth = child.getMeasuredWidth();
|
||||||
int measuredHeight = child.getMeasuredHeight();
|
int measuredHeight = child.getMeasuredHeight();
|
||||||
|
|
||||||
int width = childRight - childLeft;
|
int width = childRight - childLeft;
|
||||||
int height = childBottom - childTop;
|
int height = childBottom - childTop;
|
||||||
if ((Math.abs(measuredWidth - width) > 1 && canChangeWidth) || (Math.abs(measuredHeight - height) > 1 && canChangeHeight)) {
|
if ((Math.abs(measuredWidth - width) > 1 && canChangeWidth) || (Math.abs(measuredHeight - height) > 1 && canChangeHeight)) {
|
||||||
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(canChangeWidth ? width : lp.width, MeasureSpec.EXACTLY);
|
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(canChangeWidth ? width : lp.width, MeasureSpec.EXACTLY);
|
||||||
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(canChangeHeight ? height : lp.height, MeasureSpec.EXACTLY);
|
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(canChangeHeight ? height : lp.height, MeasureSpec.EXACTLY);
|
||||||
if (debuggable > 0) {
|
if (debuggable > 0) {
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
sb.append("remeasure ");
|
sb.append("remeasure ");
|
||||||
sb.append(child);
|
sb.append(child);
|
||||||
sb.append(" with ");
|
sb.append(" with ");
|
||||||
sb.append(MeasureSpec.toString(widthMeasureSpec));
|
sb.append(MeasureSpec.toString(widthMeasureSpec));
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append(MeasureSpec.toString(heightMeasureSpec));
|
sb.append(MeasureSpec.toString(heightMeasureSpec));
|
||||||
log(TAG, sb.toString());
|
log(TAG, sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
child.measure(widthMeasureSpec, heightMeasureSpec);
|
child.measure(widthMeasureSpec, heightMeasureSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debuggable > 0) {
|
if (debuggable > 0) {
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
sb.append(child.getParent().toString());
|
sb.append(child.getParent().toString());
|
||||||
sb.append(" :layoutChild: ");
|
sb.append(" :layoutChild: ");
|
||||||
sb.append(child.toString());
|
sb.append(child.toString());
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
sb.append(childLeft);
|
sb.append(childLeft);
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append(childTop);
|
sb.append(childTop);
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append(childRight);
|
sb.append(childRight);
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append(childBottom);
|
sb.append(childBottom);
|
||||||
log(TAG, sb.toString());
|
log(TAG, sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
child.layout(childLeft, childTop, childRight, childBottom);
|
child.layout(childLeft, childTop, childRight, childBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void measureChild(View child, int widthMeasureSpec, int heightMeasureSpec) {
|
protected static void measureChild(View child, int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
if (child.getVisibility() == View.GONE) {
|
if (child.getVisibility() == View.GONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negative means not initialized.
|
// Negative means not initialized.
|
||||||
if(debuggable < 0) {
|
if (debuggable < 0) {
|
||||||
try {
|
try {
|
||||||
Context context = child.getContext();
|
Context context = child.getContext();
|
||||||
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), android.content.pm.PackageManager.GET_META_DATA);
|
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), android.content.pm.PackageManager.GET_META_DATA);
|
||||||
android.os.Bundle bundle = ai.metaData;
|
android.os.Bundle bundle = ai.metaData;
|
||||||
Boolean debugLayouts = bundle != null ? bundle.getBoolean("debugLayouts", false) : false;
|
Boolean debugLayouts = bundle != null ? bundle.getBoolean("debugLayouts", false) : false;
|
||||||
debuggable = debugLayouts ? 1 : 0;
|
debuggable = debugLayouts ? 1 : 0;
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
debuggable = 0;
|
debuggable = 0;
|
||||||
Log.e(TAG, "Failed to load meta-data, NameNotFound: " + e.getMessage());
|
Log.e(TAG, "Failed to load meta-data, NameNotFound: " + e.getMessage());
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
debuggable = 0;
|
debuggable = 0;
|
||||||
Log.e(TAG, "Failed to load meta-data, NullPointer: " + e.getMessage());
|
Log.e(TAG, "Failed to load meta-data, NullPointer: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int childWidthMeasureSpec = getMeasureSpec(child, widthMeasureSpec, true);
|
int childWidthMeasureSpec = getMeasureSpec(child, widthMeasureSpec, true);
|
||||||
int childHeightMeasureSpec = getMeasureSpec(child, heightMeasureSpec, false);
|
int childHeightMeasureSpec = getMeasureSpec(child, heightMeasureSpec, false);
|
||||||
|
|
||||||
if (debuggable > 0) {
|
if (debuggable > 0) {
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
sb.append(child.getParent().toString());
|
sb.append(child.getParent().toString());
|
||||||
sb.append(" :measureChild: ");
|
sb.append(" :measureChild: ");
|
||||||
sb.append(child.toString());
|
sb.append(child.toString());
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
sb.append(MeasureSpec.toString(childWidthMeasureSpec));
|
sb.append(MeasureSpec.toString(childWidthMeasureSpec));
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append(MeasureSpec.toString(childHeightMeasureSpec));
|
sb.append(MeasureSpec.toString(childHeightMeasureSpec));
|
||||||
log(TAG, sb.toString());
|
log(TAG, sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
|
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateChildLayoutParams(View child, int widthMeasureSpec, int heightMeasureSpec) {
|
/**
|
||||||
|
* Iterates over children and changes their width and height to one calculated from percentage
|
||||||
int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
|
* values.
|
||||||
int widthSpec = MeasureSpec.getMode(widthMeasureSpec);
|
*
|
||||||
|
* @param viewGroup The parent ViewGroup.
|
||||||
int availableHeight = MeasureSpec.getSize(heightMeasureSpec);
|
* @param widthMeasureSpec Width MeasureSpec of the parent ViewGroup.
|
||||||
int heightSpec = MeasureSpec.getMode(heightMeasureSpec);
|
* @param heightMeasureSpec Height MeasureSpec of the parent ViewGroup.
|
||||||
|
*/
|
||||||
CommonLayoutParams lp = (CommonLayoutParams)child.getLayoutParams();
|
protected static void adjustChildrenLayoutParams(ViewGroup viewGroup, int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
if (widthSpec != MeasureSpec.UNSPECIFIED) {
|
|
||||||
if (lp.widthPercent > 0) {
|
int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
lp.width = (int)(availableWidth * lp.widthPercent);
|
int widthSpec = MeasureSpec.getMode(widthMeasureSpec);
|
||||||
}
|
|
||||||
|
int availableHeight = MeasureSpec.getSize(heightMeasureSpec);
|
||||||
if (lp.leftMarginPercent > 0) {
|
int heightSpec = MeasureSpec.getMode(heightMeasureSpec);
|
||||||
lp.leftMargin = (int)(availableWidth * lp.leftMarginPercent);
|
|
||||||
}
|
for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
|
||||||
|
View child = viewGroup.getChildAt(i);
|
||||||
if (lp.rightMarginPercent > 0) {
|
ViewGroup.LayoutParams params = child.getLayoutParams();
|
||||||
lp.rightMargin = (int)(availableWidth * lp.rightMarginPercent);
|
|
||||||
}
|
if (params instanceof CommonLayoutParams) {
|
||||||
}
|
CommonLayoutParams lp = (CommonLayoutParams) child.getLayoutParams();
|
||||||
|
if (widthSpec != MeasureSpec.UNSPECIFIED) {
|
||||||
if (heightSpec != MeasureSpec.UNSPECIFIED) {
|
if (lp.widthPercent > 0) {
|
||||||
if (lp.heightPercent > 0) {
|
lp.widthOriginal = lp.width;
|
||||||
lp.height = (int)(availableHeight * lp.heightPercent);
|
lp.width = (int) (availableWidth * lp.widthPercent);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (lp.topMarginPercent > 0) {
|
lp.widthOriginal = -1;
|
||||||
lp.topMargin = (int)(availableHeight * lp.topMarginPercent);
|
}
|
||||||
}
|
|
||||||
|
if (lp.leftMarginPercent > 0) {
|
||||||
if (lp.bottomMarginPercent > 0) {
|
lp.leftMarginOriginal = lp.leftMargin;
|
||||||
lp.bottomMargin = (int)(availableHeight * lp.bottomMarginPercent);
|
lp.leftMargin = (int) (availableWidth * lp.leftMarginPercent);
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
lp.leftMarginOriginal = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lp.rightMarginPercent > 0) {
|
||||||
|
lp.rightMarginOriginal = lp.rightMargin;
|
||||||
|
lp.rightMargin = (int) (availableWidth * lp.rightMarginPercent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lp.rightMarginOriginal = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heightSpec != MeasureSpec.UNSPECIFIED) {
|
||||||
|
if (lp.heightPercent > 0) {
|
||||||
|
lp.heightOriginal = lp.height;
|
||||||
|
lp.height = (int) (availableHeight * lp.heightPercent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lp.heightOriginal = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lp.topMarginPercent > 0) {
|
||||||
|
lp.topMarginOriginal = lp.topMargin;
|
||||||
|
lp.topMargin = (int) (availableHeight * lp.topMarginPercent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lp.topMarginOriginal = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lp.bottomMarginPercent > 0) {
|
||||||
|
lp.bottomMarginOriginal = lp.bottomMargin;
|
||||||
|
lp.bottomMargin = (int) (availableHeight * lp.bottomMarginPercent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lp.bottomMarginOriginal = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log(String tag, String message) {
|
/**
|
||||||
|
* Iterates over children and restores their original dimensions that were changed for
|
||||||
|
* percentage values.
|
||||||
|
*/
|
||||||
|
protected static void restoreOriginalParams(ViewGroup viewGroup) {
|
||||||
|
for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
|
||||||
|
View view = viewGroup.getChildAt(i);
|
||||||
|
ViewGroup.LayoutParams params = view.getLayoutParams();
|
||||||
|
if (params instanceof CommonLayoutParams) {
|
||||||
|
CommonLayoutParams lp = (CommonLayoutParams) params;
|
||||||
|
if (lp.widthPercent > 0) {
|
||||||
|
lp.width = lp.widthOriginal;
|
||||||
|
}
|
||||||
|
if (lp.heightPercent > 0) {
|
||||||
|
lp.height = lp.heightOriginal;
|
||||||
|
}
|
||||||
|
if (lp.leftMarginPercent > 0) {
|
||||||
|
lp.leftMargin = lp.leftMarginOriginal;
|
||||||
|
}
|
||||||
|
if (lp.topMarginPercent > 0) {
|
||||||
|
lp.topMargin = lp.topMarginOriginal;
|
||||||
|
}
|
||||||
|
if (lp.rightMarginPercent > 0) {
|
||||||
|
lp.rightMargin = lp.rightMarginOriginal;
|
||||||
|
}
|
||||||
|
if (lp.bottomMarginPercent > 0) {
|
||||||
|
lp.bottomMargin = lp.bottomMarginOriginal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void log(String tag, String message) {
|
||||||
Log.d(tag, message);
|
Log.d(tag, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringBuilder getStringBuilder() {
|
static StringBuilder getStringBuilder() {
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getMeasureSpec(View view, int parentMeasureSpec, boolean horizontal) {
|
private static int getMeasureSpec(View view, int parentMeasureSpec, boolean horizontal) {
|
||||||
|
|
||||||
int parentLength = MeasureSpec.getSize(parentMeasureSpec);
|
int parentLength = MeasureSpec.getSize(parentMeasureSpec);
|
||||||
int parentSpecMode = MeasureSpec.getMode(parentMeasureSpec);
|
int parentSpecMode = MeasureSpec.getMode(parentMeasureSpec);
|
||||||
|
|
||||||
CommonLayoutParams lp = (CommonLayoutParams)view.getLayoutParams();
|
CommonLayoutParams lp = (CommonLayoutParams) view.getLayoutParams();
|
||||||
final int margins = horizontal ? lp.leftMargin + lp.rightMargin : lp.topMargin + lp.bottomMargin;
|
final int margins = horizontal ? lp.leftMargin + lp.rightMargin : lp.topMargin + lp.bottomMargin;
|
||||||
|
|
||||||
int resultSize = 0;
|
int resultSize = 0;
|
||||||
int resultMode = 0;
|
int resultMode = MeasureSpec.UNSPECIFIED;
|
||||||
|
|
||||||
int measureLength = Math.max(0, parentLength - margins);
|
int measureLength = Math.max(0, parentLength - margins);
|
||||||
int childLength = horizontal ? lp.width : lp.height;
|
int childLength = horizontal ? lp.width : lp.height;
|
||||||
@@ -285,27 +364,24 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams {
|
|||||||
if (childLength >= 0) {
|
if (childLength >= 0) {
|
||||||
if (parentSpecMode != MeasureSpec.UNSPECIFIED) {
|
if (parentSpecMode != MeasureSpec.UNSPECIFIED) {
|
||||||
resultSize = Math.min(parentLength, childLength);
|
resultSize = Math.min(parentLength, childLength);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
resultSize = childLength;
|
resultSize = childLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
resultMode = MeasureSpec.EXACTLY;
|
resultMode = MeasureSpec.EXACTLY;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
switch (parentSpecMode) {
|
switch (parentSpecMode) {
|
||||||
// Parent has imposed an exact size on us
|
// Parent has imposed an exact size on us
|
||||||
case MeasureSpec.EXACTLY:
|
case MeasureSpec.EXACTLY:
|
||||||
resultSize = measureLength;
|
resultSize = measureLength;
|
||||||
int gravity = LayoutBase.getGravity(view);
|
int gravity = LayoutBase.getGravity(view);
|
||||||
boolean stretched;
|
boolean stretched;
|
||||||
if (horizontal) {
|
if (horizontal) {
|
||||||
final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, view.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
|
final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, view.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
|
||||||
stretched = horizontalGravity == Gravity.FILL_HORIZONTAL;
|
stretched = horizontalGravity == Gravity.FILL_HORIZONTAL;
|
||||||
}
|
} else {
|
||||||
else {
|
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
||||||
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
stretched = verticalGravity == Gravity.FILL_VERTICAL;
|
||||||
stretched = verticalGravity == Gravity.FILL_VERTICAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if stretched - view wants to be our size. So be it.
|
// if stretched - view wants to be our size. So be it.
|
||||||
@@ -328,4 +404,4 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams {
|
|||||||
|
|
||||||
return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
|
return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,8 @@ public class ContentLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
||||||
int measureWidth = 0;
|
int measureWidth = 0;
|
||||||
int measureHeight = 0;
|
int measureHeight = 0;
|
||||||
|
|
||||||
@@ -29,7 +30,6 @@ public class ContentLayout extends LayoutBase {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
CommonLayoutParams.measureChild(child, widthMeasureSpec, heightMeasureSpec);
|
CommonLayoutParams.measureChild(child, widthMeasureSpec, heightMeasureSpec);
|
||||||
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
||||||
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
||||||
@@ -54,7 +54,6 @@ public class ContentLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
|
||||||
int paddingLeft = this.getPaddingLeft();
|
int paddingLeft = this.getPaddingLeft();
|
||||||
int paddingRight = this.getPaddingRight();
|
int paddingRight = this.getPaddingRight();
|
||||||
int paddingTop = this.getPaddingTop();
|
int paddingTop = this.getPaddingTop();
|
||||||
@@ -75,5 +74,7 @@ public class ContentLayout extends LayoutBase {
|
|||||||
|
|
||||||
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childBottom);
|
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommonLayoutParams.restoreOriginalParams(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class DockLayout extends LayoutBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
||||||
int measureWidth = 0;
|
int measureWidth = 0;
|
||||||
int measureHeight = 0;
|
int measureHeight = 0;
|
||||||
@@ -64,7 +65,6 @@ public class DockLayout extends LayoutBase {
|
|||||||
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(remainingHeight, heightMode == MeasureSpec.EXACTLY ? MeasureSpec.AT_MOST : heightMode);
|
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(remainingHeight, heightMode == MeasureSpec.EXACTLY ? MeasureSpec.AT_MOST : heightMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec);
|
CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec);
|
||||||
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
||||||
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
||||||
@@ -107,7 +107,6 @@ public class DockLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
|
||||||
int childLeft = this.getPaddingLeft();
|
int childLeft = this.getPaddingLeft();
|
||||||
int childTop = this.getPaddingTop();
|
int childTop = this.getPaddingTop();
|
||||||
|
|
||||||
@@ -173,5 +172,7 @@ public class DockLayout extends LayoutBase {
|
|||||||
if (childToStretch != null) {
|
if (childToStretch != null) {
|
||||||
CommonLayoutParams.layoutChild(childToStretch, x, y, x + remainingWidth, y + remainingHeight);
|
CommonLayoutParams.layoutChild(childToStretch, x, y, x + remainingWidth, y + remainingHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommonLayoutParams.restoreOriginalParams(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,8 +232,9 @@ public class GridLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
||||||
int measureWidth = 0;
|
int measureWidth = 0;
|
||||||
int measureHeight = 0;
|
int measureHeight = 0;
|
||||||
|
|
||||||
int width = View.MeasureSpec.getSize(widthMeasureSpec);
|
int width = View.MeasureSpec.getSize(widthMeasureSpec);
|
||||||
@@ -251,7 +252,7 @@ public class GridLayout extends LayoutBase {
|
|||||||
this.helper.width = width - horizontalPadding;
|
this.helper.width = width - horizontalPadding;
|
||||||
this.helper.height = height - verticalPadding;
|
this.helper.height = height - verticalPadding;
|
||||||
|
|
||||||
int gravity = getGravity(this);
|
int gravity = LayoutBase.getGravity(this);
|
||||||
int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
||||||
final int layoutDirection = this.getLayoutDirection();
|
final int layoutDirection = this.getLayoutDirection();
|
||||||
final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection) & Gravity.HORIZONTAL_GRAVITY_MASK;
|
final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection) & Gravity.HORIZONTAL_GRAVITY_MASK;
|
||||||
@@ -272,7 +273,6 @@ public class GridLayout extends LayoutBase {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
MeasureSpecs measureSpecs = this.map.get(child);
|
MeasureSpecs measureSpecs = this.map.get(child);
|
||||||
this.updateMeasureSpecs(child, measureSpecs);
|
this.updateMeasureSpecs(child, measureSpecs);
|
||||||
this.helper.addMeasureSpec(measureSpecs);
|
this.helper.addMeasureSpec(measureSpecs);
|
||||||
@@ -296,7 +296,6 @@ public class GridLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
|
|
||||||
int paddingLeft = this.getPaddingLeft();
|
int paddingLeft = this.getPaddingLeft();
|
||||||
int paddingTop = this.getPaddingTop();
|
int paddingTop = this.getPaddingTop();
|
||||||
|
|
||||||
@@ -356,6 +355,8 @@ public class GridLayout extends LayoutBase {
|
|||||||
CommonLayoutParams.layoutChild(measureSpec.child, childLeft, childTop, childRight, childBottom);
|
CommonLayoutParams.layoutChild(measureSpec.child, childLeft, childTop, childRight, childBottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommonLayoutParams.restoreOriginalParams(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,9 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
// Don't call measure because it will measure content twice.
|
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
||||||
|
// Don't call measure because it will measure content twice.
|
||||||
// ScrollView is expected to have single child so we measure only the first child.
|
// ScrollView is expected to have single child so we measure only the first child.
|
||||||
View child = this.getChildCount() > 0 ? this.getChildAt(0) : null;
|
View child = this.getChildCount() > 0 ? this.getChildAt(0) : null;
|
||||||
if (child == null) {
|
if (child == null) {
|
||||||
@@ -74,7 +76,6 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
|
|||||||
this.contentMeasuredHeight = 0;
|
this.contentMeasuredHeight = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
CommonLayoutParams.measureChild(child, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), heightMeasureSpec);
|
CommonLayoutParams.measureChild(child, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), heightMeasureSpec);
|
||||||
this.contentMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
this.contentMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
||||||
this.contentMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
this.contentMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
||||||
@@ -86,8 +87,8 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
|
|||||||
|
|
||||||
// Don't add in our paddings because they are already added as child margins. (we will include them twice if we add them).
|
// Don't add in our paddings because they are already added as child margins. (we will include them twice if we add them).
|
||||||
// Check the previous line - this.setPadding(lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
|
// Check the previous line - this.setPadding(lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
|
||||||
// this.contentMeasuredWidth += this.getPaddingLeft() + this.getPaddingRight();
|
//this.contentMeasuredWidth += this.getPaddingLeft() + this.getPaddingRight();
|
||||||
// this.contentMeasuredHeight += this.getPaddingTop() + this.getPaddingBottom();
|
//this.contentMeasuredHeight += this.getPaddingTop() + this.getPaddingBottom();
|
||||||
|
|
||||||
// Check against our minimum height
|
// Check against our minimum height
|
||||||
this.contentMeasuredWidth = Math.max(this.contentMeasuredWidth, this.getSuggestedMinimumWidth());
|
this.contentMeasuredWidth = Math.max(this.contentMeasuredWidth, this.getSuggestedMinimumWidth());
|
||||||
@@ -147,6 +148,7 @@ public class HorizontalScrollView extends android.widget.HorizontalScrollView {
|
|||||||
|
|
||||||
// Calling this with the present values causes it to re-claim them
|
// Calling this with the present values causes it to re-claim them
|
||||||
this.scrollTo(scrollX, scrollY);
|
this.scrollTo(scrollX, scrollY);
|
||||||
|
CommonLayoutParams.restoreOriginalParams(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ public class StackLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
int childState = 0;
|
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
||||||
|
int childState = 0;
|
||||||
int measureWidth = 0;
|
int measureWidth = 0;
|
||||||
int measureHeight = 0;
|
int measureHeight = 0;
|
||||||
|
|
||||||
@@ -77,7 +79,6 @@ public class StackLayout extends LayoutBase {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
if (isVertical) {
|
if (isVertical) {
|
||||||
CommonLayoutParams.measureChild(child, childMeasureSpec, MeasureSpec.makeMeasureSpec(remainingLength, measureSpecMode));
|
CommonLayoutParams.measureChild(child, childMeasureSpec, MeasureSpec.makeMeasureSpec(remainingLength, measureSpecMode));
|
||||||
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
||||||
@@ -118,13 +119,14 @@ public class StackLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
|
|
||||||
if (this._orientation == Orientation.vertical) {
|
if (this._orientation == Orientation.vertical) {
|
||||||
this.layoutVertical(l, t, r, b);
|
this.layoutVertical(l, t, r, b);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.layoutHorizontal(l, t, r, b);
|
this.layoutHorizontal(l, t, r, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommonLayoutParams.restoreOriginalParams(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void layoutVertical(int left, int top, int right, int bottom) {
|
private void layoutVertical(int left, int top, int right, int bottom) {
|
||||||
@@ -138,7 +140,7 @@ public class StackLayout extends LayoutBase {
|
|||||||
int childLeft = paddingLeft;
|
int childLeft = paddingLeft;
|
||||||
int childRight = right - left - paddingRight;
|
int childRight = right - left - paddingRight;
|
||||||
|
|
||||||
int gravity = getGravity(this);
|
int gravity = LayoutBase.getGravity(this);
|
||||||
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
||||||
|
|
||||||
switch (verticalGravity) {
|
switch (verticalGravity) {
|
||||||
@@ -164,8 +166,7 @@ public class StackLayout extends LayoutBase {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonLayoutParams childLayoutParams = (CommonLayoutParams)child.getLayoutParams();
|
int childHeight = CommonLayoutParams.getDesiredHeight(child);
|
||||||
int childHeight = child.getMeasuredHeight() + childLayoutParams.topMargin + childLayoutParams.bottomMargin;
|
|
||||||
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childTop + childHeight);
|
CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childTop + childHeight);
|
||||||
childTop += childHeight;
|
childTop += childHeight;
|
||||||
}
|
}
|
||||||
@@ -183,7 +184,7 @@ public class StackLayout extends LayoutBase {
|
|||||||
int childLeft = 0;
|
int childLeft = 0;
|
||||||
int childBottom = bottom - top - paddingBottom;
|
int childBottom = bottom - top - paddingBottom;
|
||||||
|
|
||||||
int gravity = getGravity(this);
|
int gravity = LayoutBase.getGravity(this);
|
||||||
final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, this.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
|
final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, this.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
|
||||||
|
|
||||||
switch (horizontalGravity) {
|
switch (horizontalGravity) {
|
||||||
@@ -209,8 +210,7 @@ public class StackLayout extends LayoutBase {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonLayoutParams childLayoutParams = (CommonLayoutParams)child.getLayoutParams();
|
int childWidth = CommonLayoutParams.getDesiredWidth(child);
|
||||||
int childWidth = child.getMeasuredWidth() + childLayoutParams.leftMargin + childLayoutParams.rightMargin;
|
|
||||||
CommonLayoutParams.layoutChild(child, childLeft, childTop, childLeft + childWidth, childBottom);
|
CommonLayoutParams.layoutChild(child, childLeft, childTop, childLeft + childWidth, childBottom);
|
||||||
childLeft += childWidth;
|
childLeft += childWidth;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import android.view.View;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
class TabStrip extends LinearLayout {
|
class TabStrip extends LinearLayout {
|
||||||
|
|
||||||
private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0;
|
private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0;
|
||||||
private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
|
private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
|
||||||
private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3;
|
private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3;
|
||||||
@@ -53,13 +53,14 @@ class TabStrip extends LinearLayout {
|
|||||||
|
|
||||||
TabStrip(Context context, AttributeSet attrs) {
|
TabStrip(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
setWillNotDraw(false);
|
setWillNotDraw(false);
|
||||||
|
|
||||||
final float density = getResources().getDisplayMetrics().density;
|
final float density = getResources().getDisplayMetrics().density;
|
||||||
|
|
||||||
TypedValue outValue = new TypedValue();
|
TypedValue outValue = new TypedValue();
|
||||||
context.getTheme().resolveAttribute(android.R.attr.colorForeground, outValue, true);
|
context.getTheme().resolveAttribute(android.R.attr.colorForeground, outValue, true);
|
||||||
final int themeForegroundColor = outValue.data;
|
final int themeForegroundColor = outValue.data;
|
||||||
|
|
||||||
mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
|
mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
|
||||||
DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
|
DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
|
||||||
|
|||||||
@@ -65,7 +65,9 @@ public class VerticalScrollView extends ScrollView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
// Don't call measure because it will measure content twice.
|
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
|
||||||
|
|
||||||
|
// Don't call measure because it will measure content twice.
|
||||||
// ScrollView is expected to have single child so we measure only the first child.
|
// ScrollView is expected to have single child so we measure only the first child.
|
||||||
View child = this.getChildCount() > 0 ? this.getChildAt(0) : null;
|
View child = this.getChildCount() > 0 ? this.getChildAt(0) : null;
|
||||||
if (child == null) {
|
if (child == null) {
|
||||||
@@ -75,7 +77,6 @@ public class VerticalScrollView extends ScrollView {
|
|||||||
this.setPadding(0, 0, 0, 0);
|
this.setPadding(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
CommonLayoutParams.measureChild(child, widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
CommonLayoutParams.measureChild(child, widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
||||||
this.contentMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
this.contentMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
||||||
this.contentMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
this.contentMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
||||||
@@ -144,6 +145,8 @@ public class VerticalScrollView extends ScrollView {
|
|||||||
|
|
||||||
// Calling this with the present values causes it to re-claim them
|
// Calling this with the present values causes it to re-claim them
|
||||||
this.scrollTo(scrollX, scrollY);
|
this.scrollTo(scrollX, scrollY);
|
||||||
|
|
||||||
|
CommonLayoutParams.restoreOriginalParams(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -60,8 +60,9 @@ public class WrapLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
CommonLayoutParams.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
|
||||||
int measureWidth = 0;
|
|
||||||
|
int measureWidth = 0;
|
||||||
int measureHeight = 0;
|
int measureHeight = 0;
|
||||||
|
|
||||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
@@ -91,8 +92,7 @@ public class WrapLayout extends LayoutBase {
|
|||||||
if (child.getVisibility() == View.GONE) {
|
if (child.getVisibility() == View.GONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonLayoutParams.updateChildLayoutParams(child, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec);
|
CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec);
|
||||||
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
final int childMeasuredWidth = CommonLayoutParams.getDesiredWidth(child);
|
||||||
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
final int childMeasuredHeight = CommonLayoutParams.getDesiredHeight(child);
|
||||||
@@ -162,7 +162,6 @@ public class WrapLayout extends LayoutBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
|
||||||
boolean isVertical = this._orientation == Orientation.vertical;
|
boolean isVertical = this._orientation == Orientation.vertical;
|
||||||
int paddingLeft = this.getPaddingLeft();
|
int paddingLeft = this.getPaddingLeft();
|
||||||
int paddingRight = this.getPaddingRight();
|
int paddingRight = this.getPaddingRight();
|
||||||
@@ -187,7 +186,6 @@ public class WrapLayout extends LayoutBase {
|
|||||||
|
|
||||||
int length = this._lengths.get(rowOrColumn);
|
int length = this._lengths.get(rowOrColumn);
|
||||||
if (isVertical) {
|
if (isVertical) {
|
||||||
|
|
||||||
childWidth = length;
|
childWidth = length;
|
||||||
childHeight = this._itemHeight > 0 ? this._itemHeight : childHeight;
|
childHeight = this._itemHeight > 0 ? this._itemHeight : childHeight;
|
||||||
if (childTop + childHeight > childrenLength) {
|
if (childTop + childHeight > childrenLength) {
|
||||||
@@ -233,5 +231,7 @@ public class WrapLayout extends LayoutBase {
|
|||||||
childLeft += childWidth;
|
childLeft += childWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommonLayoutParams.restoreOriginalParams(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,23 +65,14 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||||
@@ -92,5 +83,6 @@
|
|||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
|
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
|
||||||
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
|
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="android-android-17" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
Reference in New Issue
Block a user