diff --git a/api/current.txt b/api/current.txt index edce92a4eb23f..61e88a3f0c699 100644 --- a/api/current.txt +++ b/api/current.txt @@ -179,9 +179,9 @@ package android { public static final class R.attr { ctor public R.attr(); field public static final int absListViewStyle = 16842858; // 0x101006a - field public static final int accessibilityEventTypes = 16843645; // 0x101037d - field public static final int accessibilityFeedbackType = 16843647; // 0x101037f - field public static final int accessibilityFlags = 16843649; // 0x1010381 + field public static final int accessibilityEventTypes = 16843646; // 0x101037e + field public static final int accessibilityFeedbackType = 16843648; // 0x1010380 + field public static final int accessibilityFlags = 16843650; // 0x1010382 field public static final int accountPreferences = 16843423; // 0x101029f field public static final int accountType = 16843407; // 0x101028f field public static final int action = 16842797; // 0x101002d @@ -201,7 +201,7 @@ package android { field public static final int actionModeCopyDrawable = 16843538; // 0x1010312 field public static final int actionModeCutDrawable = 16843537; // 0x1010311 field public static final int actionModePasteDrawable = 16843539; // 0x1010313 - field public static final int actionModeSelectAllDrawable = 16843643; // 0x101037b + field public static final int actionModeSelectAllDrawable = 16843644; // 0x101037c field public static final int actionOverflowButtonStyle = 16843510; // 0x10102f6 field public static final int actionViewClass = 16843516; // 0x10102fc field public static final int activatedBackgroundIndicator = 16843517; // 0x10102fd @@ -273,7 +273,7 @@ package android { field public static final int cacheColorHint = 16843009; // 0x1010101 field public static final int calendarViewShown = 16843596; // 0x101034c field public static final int calendarViewStyle = 16843613; // 0x101035d - field public static final int canRetrieveWindowContent = 16843650; // 0x1010382 + field public static final int canRetrieveWindowContent = 16843651; // 0x1010383 field public static final int candidatesTextStyleSpans = 16843312; // 0x1010230 field public static final deprecated int capitalize = 16843113; // 0x1010169 field public static final int centerBright = 16842956; // 0x10100cc @@ -532,7 +532,7 @@ package android { field public static final int installLocation = 16843447; // 0x10102b7 field public static final int interpolator = 16843073; // 0x1010141 field public static final int isAlwaysSyncable = 16843571; // 0x1010333 - field public static final int isAuxiliary = 16843644; // 0x101037c + field public static final int isAuxiliary = 16843645; // 0x101037d field public static final int isDefault = 16843297; // 0x1010221 field public static final int isIndicator = 16843079; // 0x1010147 field public static final int isModifier = 16843334; // 0x1010246 @@ -584,8 +584,8 @@ package android { field public static final int layout_centerInParent = 16843151; // 0x101018f field public static final int layout_centerVertical = 16843153; // 0x1010191 field public static final int layout_column = 16843084; // 0x101014c - field public static final int layout_columnSpan = 16843641; // 0x1010379 - field public static final int layout_columnWeight = 16843642; // 0x101037a + field public static final int layout_columnSpan = 16843642; // 0x101037a + field public static final int layout_columnWeight = 16843643; // 0x101037b field public static final int layout_gravity = 16842931; // 0x10100b3 field public static final int layout_height = 16842997; // 0x10100f5 field public static final int layout_margin = 16842998; // 0x10100f6 @@ -593,9 +593,9 @@ package android { field public static final int layout_marginLeft = 16842999; // 0x10100f7 field public static final int layout_marginRight = 16843001; // 0x10100f9 field public static final int layout_marginTop = 16843000; // 0x10100f8 - field public static final int layout_row = 16843638; // 0x1010376 - field public static final int layout_rowSpan = 16843639; // 0x1010377 - field public static final int layout_rowWeight = 16843640; // 0x1010378 + field public static final int layout_row = 16843639; // 0x1010377 + field public static final int layout_rowSpan = 16843640; // 0x1010378 + field public static final int layout_rowWeight = 16843641; // 0x1010379 field public static final int layout_scale = 16843155; // 0x1010193 field public static final int layout_span = 16843085; // 0x101014d field public static final int layout_toLeftOf = 16843138; // 0x1010182 @@ -625,6 +625,7 @@ package android { field public static final int loopViews = 16843527; // 0x1010307 field public static final int manageSpaceActivity = 16842756; // 0x1010004 field public static final int mapViewStyle = 16842890; // 0x101008a + field public static final int marginsIncludedInAlignment = 16843638; // 0x1010376 field public static final int marqueeRepeatLimit = 16843293; // 0x101021d field public static final int max = 16843062; // 0x1010136 field public static final int maxDate = 16843584; // 0x1010340 @@ -661,7 +662,7 @@ package android { field public static final int nextFocusUp = 16842979; // 0x10100e3 field public static final int noHistory = 16843309; // 0x101022d field public static final int normalScreens = 16843397; // 0x1010285 - field public static final int notificationTimeout = 16843648; // 0x1010380 + field public static final int notificationTimeout = 16843649; // 0x1010381 field public static final int numColumns = 16843032; // 0x1010118 field public static final int numStars = 16843076; // 0x1010144 field public static final deprecated int numeric = 16843109; // 0x1010165 @@ -678,7 +679,7 @@ package android { field public static final int overScrollFooter = 16843459; // 0x10102c3 field public static final int overScrollHeader = 16843458; // 0x10102c2 field public static final int overScrollMode = 16843457; // 0x10102c1 - field public static final int packageNames = 16843646; // 0x101037e + field public static final int packageNames = 16843647; // 0x101037f field public static final int padding = 16842965; // 0x10100d5 field public static final int paddingBottom = 16842969; // 0x10100d9 field public static final int paddingLeft = 16842966; // 0x10100d6 @@ -24533,6 +24534,7 @@ package android.widget { ctor public GridLayout(android.content.Context, android.util.AttributeSet, int); ctor public GridLayout(android.content.Context, android.util.AttributeSet); method public int getColumnCount(); + method public boolean getMarginsIncludedInAlignment(); method public int getOrientation(); method public int getRowCount(); method public boolean getUseDefaultMargins(); @@ -24541,6 +24543,7 @@ package android.widget { method protected void onLayout(boolean, int, int, int, int); method public void setColumnCount(int); method public void setColumnOrderPreserved(boolean); + method public void setMarginsIncludedInAlignment(boolean); method public void setOrientation(int); method public void setRowCount(int); method public void setRowOrderPreserved(boolean); @@ -24553,6 +24556,7 @@ package android.widget { field public static final android.widget.GridLayout.Alignment LEFT; field public static final android.widget.GridLayout.Alignment RIGHT; field public static final android.widget.GridLayout.Alignment TOP; + field public static final int UNDEFINED = -2147483648; // 0x80000000 field public static final int VERTICAL = 1; // 0x1 } @@ -24562,17 +24566,9 @@ package android.widget { } public static class GridLayout.Group { - ctor public GridLayout.Group(android.widget.GridLayout.Interval, android.widget.GridLayout.Alignment); ctor public GridLayout.Group(int, int, android.widget.GridLayout.Alignment); ctor public GridLayout.Group(int, android.widget.GridLayout.Alignment); field public final android.widget.GridLayout.Alignment alignment; - field public final android.widget.GridLayout.Interval span; - } - - public static class GridLayout.Interval { - ctor public GridLayout.Interval(int, int); - field public final int max; - field public final int min; } public static class GridLayout.LayoutParams extends android.view.ViewGroup.MarginLayoutParams { diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java index 488910152cef1..b99cd7fabcfb0 100644 --- a/core/java/android/widget/GridLayout.java +++ b/core/java/android/widget/GridLayout.java @@ -38,6 +38,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static android.view.View.MeasureSpec.EXACTLY; +import static android.view.View.MeasureSpec.UNSPECIFIED; import static java.lang.Math.max; import static java.lang.Math.min; @@ -46,7 +48,7 @@ import static java.lang.Math.min; *
* The grid is composed of a set of infinitely thin lines that separate the
* viewing area into cells. Throughout the API, grid lines are referenced
- * by grid indices. A grid that has N columns
+ * by grid indices. A grid with N columns
* has N + 1 grid indices that run from 0
* through N inclusive. Regardless of how GridLayout is
* configured, grid index 0 is fixed to the leading edge of the
@@ -116,16 +118,27 @@ public class GridLayout extends ViewGroup {
* The horizontal orientation.
*/
public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
+
/**
* The vertical orientation.
*/
public static final int VERTICAL = LinearLayout.VERTICAL;
+ /**
+ * The constant used to indicate that a value is undefined.
+ * Fields can use this value to indicate that their values
+ * have not yet been set. Similarly, methods can return this value
+ * to indicate that there is no suitable value that the implementation
+ * can return.
+ * The value used for the constant (currently {@link Integer#MIN_VALUE}) is
+ * intended to avoid confusion between valid values whose sign may not be known.
+ */
+ public static final int UNDEFINED = Integer.MIN_VALUE;
+
// Misc constants
private static final String TAG = GridLayout.class.getName();
private static final boolean DEBUG = false;
- private static final int UNDEFINED = Integer.MIN_VALUE;
private static final Paint GRID_PAINT = new Paint();
private static final double GOLDEN_RATIO = (1 + Math.sqrt(5)) / 2;
private static final int MIN = 0;
@@ -138,6 +151,9 @@ public class GridLayout extends ViewGroup {
private static final int DEFAULT_COUNT = UNDEFINED;
private static final boolean DEFAULT_USE_DEFAULT_MARGINS = false;
private static final boolean DEFAULT_ORDER_PRESERVED = false;
+ private static final boolean DEFAULT_MARGINS_INCLUDED = true;
+ // todo remove this
+ private static final int DEFAULT_CONTAINER_MARGIN = 20;
// TypedArray indices
@@ -145,9 +161,16 @@ public class GridLayout extends ViewGroup {
private static final int ROW_COUNT = styleable.GridLayout_rowCount;
private static final int COLUMN_COUNT = styleable.GridLayout_columnCount;
private static final int USE_DEFAULT_MARGINS = styleable.GridLayout_useDefaultMargins;
+ private static final int MARGINS_INCLUDED = styleable.GridLayout_marginsIncludedInAlignment;
private static final int ROW_ORDER_PRESERVED = styleable.GridLayout_rowOrderPreserved;
private static final int COLUMN_ORDER_PRESERVED = styleable.GridLayout_columnOrderPreserved;
+ // Static initialization
+
+ static {
+ GRID_PAINT.setColor(Color.argb(50, 255, 255, 255));
+ }
+
// Instance variables
private final Axis mHorizontalAxis = new Axis(true);
@@ -155,9 +178,10 @@ public class GridLayout extends ViewGroup {
private boolean mLayoutParamsValid = false;
private int mOrientation = DEFAULT_ORIENTATION;
private boolean mUseDefaultMargins = DEFAULT_USE_DEFAULT_MARGINS;
+ private boolean mMarginsIncludedInAlignment = DEFAULT_MARGINS_INCLUDED;
private int mDefaultGravity = Gravity.NO_GRAVITY;
- boolean maximizing = false;
- boolean accommodateBothMinAndMax = false;
+
+ /* package */ boolean accommodateBothMinAndMax = false;
// Constructors
@@ -194,6 +218,7 @@ public class GridLayout extends ViewGroup {
setColumnCount(a.getInteger(COLUMN_COUNT, DEFAULT_COUNT));
mOrientation = a.getInteger(ORIENTATION, DEFAULT_ORIENTATION);
mUseDefaultMargins = a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS);
+ mMarginsIncludedInAlignment = a.getBoolean(MARGINS_INCLUDED, DEFAULT_MARGINS_INCLUDED);
setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
} finally {
@@ -320,10 +345,15 @@ public class GridLayout extends ViewGroup {
* to the appropriate layout parameter.
*
* When false, the default value of all margins is zero. + *
+ * When setting to true, consider setting the value of the
+ * {@link #setMarginsIncludedInAlignment(boolean) marginsIncludedInAlignment}
+ * property to false.
*
* @param useDefaultMargins use true to make GridLayout allocate default margins
*
* @see #getUseDefaultMargins()
+ * @see #setMarginsIncludedInAlignment(boolean)
*
* @see MarginLayoutParams#leftMargin
* @see MarginLayoutParams#topMargin
@@ -334,6 +364,39 @@ public class GridLayout extends ViewGroup {
*/
public void setUseDefaultMargins(boolean useDefaultMargins) {
mUseDefaultMargins = useDefaultMargins;
+ requestLayout();
+ }
+
+ /**
+ * Returns whether GridLayout aligns the edges of the view or the edges
+ * of the larger rectangle created by extending the view by its associated
+ * margins.
+ *
+ * @see #setMarginsIncludedInAlignment(boolean)
+ *
+ * @return true if alignment is between edges including margins.
+ *
+ * @attr ref android.R.styleable#GridLayout_marginsIncludedInAlignment
+ */
+ public boolean getMarginsIncludedInAlignment() {
+ return mMarginsIncludedInAlignment;
+ }
+
+ /**
+ * When true, the bounds of a view are extended outwards according to its
+ * margins before the edges of the resulting rectangle are aligned.
+ * When false, alignment occurs between the bounds of the view - i.e.
+ * {@link #LEFT} alignment means align the left edges of the view.
+ *
+ * @param marginsIncludedInAlignment true if alignment is between edges including margins.
+ *
+ * @see #getMarginsIncludedInAlignment()
+ *
+ * @attr ref android.R.styleable#GridLayout_marginsIncludedInAlignment
+ */
+ public void setMarginsIncludedInAlignment(boolean marginsIncludedInAlignment) {
+ mMarginsIncludedInAlignment = marginsIncludedInAlignment;
+ requestLayout();
}
/**
@@ -353,11 +416,9 @@ public class GridLayout extends ViewGroup {
/**
* When this property is false, the default state, GridLayout
* is at liberty to choose an order that better suits the heights of its children.
-
- * When this property is true, GridLayout is forced to place row boundaries
- * (the {@link Interval#min min} and {@link Interval#max max} values of
- * a {@link LayoutParams#rowGroup rowGroup}'s {@link Group#span span})
- * so that they appear in ascending order in the view.
+
+ * When this property is true, GridLayout is forced to place the row boundaries
+ * so that their associated grid indices are in ascending order in the view.
*
* GridLayout implements this specification by creating ordering constraints between
* the variables that represent the locations of the row boundaries.
@@ -377,6 +438,8 @@ public class GridLayout extends ViewGroup {
*/
public void setRowOrderPreserved(boolean rowOrderPreserved) {
mVerticalAxis.setOrderPreserved(rowOrderPreserved);
+ invalidateStructure();
+ requestLayout();
}
/**
@@ -396,11 +459,9 @@ public class GridLayout extends ViewGroup {
/**
* When this property is false, the default state, GridLayout
* is at liberty to choose an order that better suits the widths of its children.
-
- * When this property is true, GridLayout is forced to place column boundaries
- * (the {@link Interval#min min} and {@link Interval#max max} values of
- * a {@link LayoutParams#columnGroup columnGroup}'s {@link Group#span span})
- * so that they appear in ascending order in the view.
+
+ * When this property is true, GridLayout is forced to place the column boundaries
+ * so that their associated grid indices are in ascending order in the view.
*
* GridLayout implements this specification by creating ordering constraints between
* the variables that represent the locations of the column boundaries.
@@ -420,13 +481,11 @@ public class GridLayout extends ViewGroup {
*/
public void setColumnOrderPreserved(boolean columnOrderPreserved) {
mHorizontalAxis.setOrderPreserved(columnOrderPreserved);
+ invalidateStructure();
+ requestLayout();
}
- private static int compare(int i, int j) {
- return i < j ? -1 : i > j ? 1 : 0;
- }
-
- private static int sum(int[] a) {
+ private static int sum(float[] a) {
int result = 0;
for (int i = 0, length = a.length; i < length; i++) {
result += a[i];
@@ -440,13 +499,12 @@ public class GridLayout extends ViewGroup {
// gaps are in the proportion of the golden ratio.
// To effect this with equal margins at each edge, set each of the
// four margin values to half this amount.
- c.measure(0, 0);
return (int) (c.getMeasuredHeight() / GOLDEN_RATIO / 2);
}
private int getDefaultMargin(View c, boolean isAtEdge, boolean leading, boolean horizontal) {
- // todo remove 20 - use padding here?
- return isAtEdge ? 20 : getDefaultMargin(c, leading, horizontal);
+ // todo remove DEFAULT_CONTAINER_MARGIN. Use padding? Seek advice on Themes/Styles, etc.
+ return isAtEdge ? DEFAULT_CONTAINER_MARGIN : getDefaultMargin(c, leading, horizontal);
}
private int getDefaultMarginValue(View c, LayoutParams p, boolean leading, boolean horizontal) {
@@ -456,7 +514,7 @@ public class GridLayout extends ViewGroup {
Group group = horizontal ? p.columnGroup : p.rowGroup;
Axis axis = horizontal ? mHorizontalAxis : mVerticalAxis;
Interval span = group.span;
- boolean isAtEdge = leading ? span.min == 0 : span.max == axis.getCount();
+ boolean isAtEdge = leading ? (span.min == 0) : (span.max == axis.getCount());
return getDefaultMargin(c, isAtEdge, leading, horizontal);
}
@@ -464,8 +522,8 @@ public class GridLayout extends ViewGroup {
private int getMargin(View view, boolean leading, boolean horizontal) {
LayoutParams lp = getLayoutParams(view);
int margin = horizontal ?
- leading ? lp.leftMargin : lp.rightMargin :
- leading ? lp.topMargin : lp.bottomMargin;
+ (leading ? lp.leftMargin : lp.rightMargin) :
+ (leading ? lp.topMargin : lp.bottomMargin);
return margin == UNDEFINED ? getDefaultMarginValue(view, lp, leading, horizontal) : margin;
}
@@ -475,7 +533,7 @@ public class GridLayout extends ViewGroup {
private void validateLayoutParams() {
// install default indices for cells if *none* are defined
- if (mHorizontalAxis.maxIndex1() == UNDEFINED || mVerticalAxis.maxIndex1() == UNDEFINED) {
+ if (mHorizontalAxis.maxIndex1() == UNDEFINED || (mVerticalAxis.maxIndex1() == UNDEFINED)) {
boolean horizontal = mOrientation == HORIZONTAL;
int count = horizontal ? mHorizontalAxis.count : mVerticalAxis.count;
if (count == UNDEFINED) {
@@ -539,14 +597,17 @@ public class GridLayout extends ViewGroup {
mLayoutParamsValid = false;
mHorizontalAxis.invalidateStructure();
mVerticalAxis.invalidateStructure();
-
// This can end up being done twice. But better that than not at all.
invalidateValues();
}
private void invalidateValues() {
- mHorizontalAxis.invalidateValues();
- mVerticalAxis.invalidateValues();
+ // Need null check because requestLayout() is called in View's initializer,
+ // before we are set up.
+ if (mHorizontalAxis != null && mVerticalAxis != null) {
+ mHorizontalAxis.invalidateValues();
+ mVerticalAxis.invalidateValues();
+ }
}
private LayoutParams getLayoutParams1(View c) {
@@ -605,10 +666,6 @@ public class GridLayout extends ViewGroup {
}
}
- static {
- GRID_PAINT.setColor(Color.argb(50, 255, 255, 255));
- }
-
// Add/remove
@Override
@@ -643,18 +700,49 @@ public class GridLayout extends ViewGroup {
// Measurement
+ private static int getChildMeasureSpec2(int spec, int padding, int childDimension) {
+ int resultSize;
+ int resultMode;
+
+ if (childDimension >= 0) {
+ resultSize = childDimension;
+ resultMode = EXACTLY;
+ } else {
+ /*
+ using the following lines would replicate the logic of ViewGroup.getChildMeasureSpec()
+
+ int specMode = MeasureSpec.getMode(spec);
+ int specSize = MeasureSpec.getSize(spec);
+ int size = Math.max(0, specSize - padding);
+
+ resultSize = size;
+ resultMode = (specMode == EXACTLY && childDimension == LayoutParams.WRAP_CONTENT) ?
+ AT_MOST : specMode;
+ */
+ resultSize = 0;
+ resultMode = UNSPECIFIED;
+ }
+ return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
+ }
+
+ @Override
+ protected void measureChild(View child, int parentWidthSpec, int parentHeightSpec) {
+ ViewGroup.LayoutParams lp = child.getLayoutParams();
+
+ int childWidthMeasureSpec = getChildMeasureSpec2(parentWidthSpec,
+ mPaddingLeft + mPaddingRight, lp.width);
+ int childHeightMeasureSpec = getChildMeasureSpec2(parentHeightSpec,
+ mPaddingTop + mPaddingBottom, lp.height);
+
+ child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
+ }
+
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
- invalidateValues();
- // int width = MeasureSpec.getSize(widthSpec);
- // int widthMode = MeasureSpec.getMode(widthSpec);
- // int height = MeasureSpec.getSize(heightSpec);
- // int heightMode = MeasureSpec.getMode(heightSpec);
+ measureChildren(widthSpec, heightSpec);
- // todo - handle widthSpec and heightSpec properly
-
- int computedWidth = getPaddingLeft() + mHorizontalAxis.getPref() + getPaddingRight();
- int computedHeight = getPaddingTop() + mVerticalAxis.getPref() + getPaddingBottom();
+ int computedWidth = getPaddingLeft() + mHorizontalAxis.getMin() + getPaddingRight();
+ int computedHeight = getPaddingTop() + mVerticalAxis.getMin() + getPaddingBottom();
setMeasuredDimension(
resolveSizeAndState(computedWidth, widthSpec, 0),
@@ -662,41 +750,54 @@ public class GridLayout extends ViewGroup {
}
private int protect(int alignment) {
- return alignment == UNDEFINED ? 0 : alignment;
- }
-
- private int getLocationIncludingMargin(Axis state, int index, boolean leading) {
- int margin = leading ? state.leadingMargins[index] : -state.trailingMargins[index];
- return state.locations[index] + margin;
+ return (alignment == UNDEFINED) ? 0 : alignment;
}
private int getMeasurement(View c, boolean horizontal, int measurementType) {
- LayoutParams lp = (LayoutParams) c.getLayoutParams();
- // First check to see if the user has specified the size.
- // If so, return the specified size.
- int size = horizontal ? lp.width : lp.height;
- if (size >= 0) {
- return size;
- }
+ return horizontal ? c.getMeasuredWidth() : c.getMeasuredHeight();
+ }
- // measureChild(c, 0, 0);
- c.measure(0, 0);// todo work out correct order of events for measurement calls
- int result = horizontal ? c.getMeasuredWidth() : c.getMeasuredHeight();
-
- float weight = horizontal ? lp.columnWeight : lp.rowWeight;
- Axis axis = horizontal ? mHorizontalAxis : mVerticalAxis;
- if (weight != 0) {
- return result + axis.prefSizeOfWeightedComponent;
+ private int getMeasurementIncludingMargin(View c, boolean horizontal, int measurementType) {
+ int result = getMeasurement(c, horizontal, measurementType);
+ if (mMarginsIncludedInAlignment) {
+ int leadingMargin = getMargin(c, true, horizontal);
+ int trailingMargin = getMargin(c, false, horizontal);
+ return result + leadingMargin + trailingMargin;
}
return result;
}
- // Layout container
+ private int getAlignmentValue(Alignment alignment, View c, int dim, boolean horizontal, View c1) {
+ int result = alignment.getAlignmentValue(c, dim);
+ if (mMarginsIncludedInAlignment) {
+ int leadingMargin = getMargin(c1, true, horizontal);
+ return result + leadingMargin;
+ }
+ return result;
+ }
@Override
- protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ public void requestLayout() {
+ super.requestLayout();
invalidateValues();
+ }
+ // Layout container
+
+ /**
+ * {@inheritDoc}
+ */
+ /*
+ The layout operation is implemented by delegating the heavy lifting to the
+ to the mHorizontalAxis and mVerticalAxis instances of the internal Axis class.
+ Together they compute the locations of the vertical and horizontal lines of
+ the grid (respectively!).
+
+ This method is then left with the simpler task of applying margins, gravity
+ and sizing to each child view and then placing it in its cell.
+ */
+ @Override
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
int targetWidth = r - l;
int targetHeight = b - t;
@@ -710,33 +811,43 @@ public class GridLayout extends ViewGroup {
for (int i = 0, size = getChildCount(); i < size; i++) {
View view = getChildAt(i);
- LayoutParams constraints = getLayoutParams(view);
- Interval hRange = constraints.columnGroup.span;
- Interval vRange = constraints.rowGroup.span;
+ LayoutParams lp = getLayoutParams(view);
+ Group columnGroup = lp.columnGroup;
+ Group rowGroup = lp.rowGroup;
- int x1 = getLocationIncludingMargin(mHorizontalAxis, hRange.min, true);
- int y1 = getLocationIncludingMargin(mVerticalAxis, vRange.min, true);
+ Interval colSpan = columnGroup.span;
+ Interval rowSpan = rowGroup.span;
- int x2 = getLocationIncludingMargin(mHorizontalAxis, hRange.max, false);
- int y2 = getLocationIncludingMargin(mVerticalAxis, vRange.max, false);
+ int x1 = mHorizontalAxis.getLocationIncludingMargin(view, true, colSpan.min);
+ int y1 = mVerticalAxis.getLocationIncludingMargin(view, true, rowSpan.min);
+
+ int x2 = mHorizontalAxis.getLocationIncludingMargin(view, false, colSpan.max);
+ int y2 = mVerticalAxis.getLocationIncludingMargin(view, false, rowSpan.max);
int cellWidth = x2 - x1;
int cellHeight = y2 - y1;
- Bounds minMaxX = mHorizontalAxis.getGroupBounds().getValue(i);
- Bounds minMaxY = mVerticalAxis.getGroupBounds().getValue(i);
-
int pWidth = getMeasurement(view, true, PRF);
int pHeight = getMeasurement(view, false, PRF);
- Alignment hAlignment = constraints.columnGroup.alignment;
- Alignment vAlignment = constraints.rowGroup.alignment;
+ Alignment hAlignment = columnGroup.alignment;
+ Alignment vAlignment = rowGroup.alignment;
- int ddx = protect(hAlignment.getAlignmentValue(null, cellWidth - minMaxX.size()));
- int ddy = protect(vAlignment.getAlignmentValue(null, cellHeight - minMaxY.size()));
+ int dx, dy;
- int dx = ddx + -minMaxX.below - hAlignment.getAlignmentValue(view, pWidth);
- int dy = ddy + -minMaxY.below - vAlignment.getAlignmentValue(view, pHeight);
+ if (mMarginsIncludedInAlignment) {
+ dx = protect(hAlignment.getAlignmentValue(view, cellWidth - pWidth));
+ dy = protect(vAlignment.getAlignmentValue(view, cellHeight - pHeight));
+ } else {
+ Bounds colBounds = mHorizontalAxis.getGroupBounds().getValue(i);
+ Bounds rowBounds = mVerticalAxis.getGroupBounds().getValue(i);
+
+ int mx = protect(hAlignment.getAlignmentValue(null, cellWidth - colBounds.size()));
+ int my = protect(vAlignment.getAlignmentValue(null, cellHeight - rowBounds.size()));
+
+ dx = mx + -colBounds.below - hAlignment.getAlignmentValue(view, pWidth);
+ dy = my + -rowBounds.below - vAlignment.getAlignmentValue(view, pHeight);
+ }
int width = hAlignment.getSizeInCell(view, pWidth, cellWidth);
int height = vAlignment.getSizeInCell(view, pHeight, cellHeight);
@@ -749,9 +860,14 @@ public class GridLayout extends ViewGroup {
// Inner classes
+ /*
+ This internal class houses the algorithm for computing the locations of grid lines;
+ along either the horizontal or vertical axis. A GridLayout uses two instances of this class -
+ distinguished by the "horizontal" flag which is true for the horizontal axis and false
+ for the vertical one.
+ */
private class Axis {
private static final int MIN_VALUE = -1000000;
- private static final int MAX_VALUE = 1000000;
private static final int UNVISITED = 0;
private static final int PENDING = 1;
@@ -766,20 +882,25 @@ public class GridLayout extends ViewGroup {
PackedMap
- * The {@link Group#span span} fields of the row and column groups together specify
- * the four grid indices that delimit the cells of this cell group.
+ * The row and column groups contain the leading and trailing indices along each axis
+ * and together specify the four grid indices that delimit the cells of this cell group.
*
* The {@link Group#alignment alignment} fields of the row and column groups together specify
* both aspects of alignment within the cell group. It is also possible to specify a child's
@@ -1277,19 +1474,19 @@ public class GridLayout extends ViewGroup {
*
* See {@link GridLayout} for a description of the conventions used by GridLayout
* for grid indices.
*/
- public final Interval span;
+ /* package */ final Interval span;
/**
* Specifies how cells should be aligned in this group.
* For row groups, this specifies the vertical alignment.
@@ -1818,7 +2047,7 @@ public class GridLayout extends ViewGroup {
* @param span the span.
* @param alignment the alignment.
*/
- public Group(Interval span, Alignment alignment) {
+ /* package */ Group(Interval span, Alignment alignment) {
this.span = span;
this.alignment = alignment;
}
@@ -1861,7 +2090,7 @@ public class GridLayout extends ViewGroup {
}
/**
- * Returns true if the {@link #getClass class}, {@link #alignment} and {@link #span}
+ * Returns true if the {@link #getClass class}, {@link #alignment} and false; otherwise {@link Integer#MIN_VALUE}, to
+ * false; otherwise {@link #UNDEFINED}, to
* indicate that a default value should be computed on demand. false; otherwise {@link Integer#MIN_VALUE}, to
+ * false; otherwise {@link #UNDEFINED}, to
* indicate that a default value should be computed on demand. false; otherwise {@link Integer#MIN_VALUE}, to
+ * false; otherwise {@link #UNDEFINED}, to
* indicate that a default value should be computed on demand. false; otherwise {@link Integer#MIN_VALUE}, to
+ * false; otherwise {@link #UNDEFINED}, to
* indicate that a default value should be computed on demand. .span = [0, 1] .alignment = {@link #BASELINE} [min, max] and represent the set of values
* x such that min <= x < max.
*/
- public static class Interval {
+ /* package */ static class Interval {
/**
* The minimum value.
*/
public final int min;
+
/**
* The maximum value.
*/
@@ -1793,14 +2023,13 @@ public class GridLayout extends ViewGroup {
*/
public static class Group {
/**
- * The {@link Interval#min min} and {@link Interval#max max} values of
- * a span specify the grid indices of the leading and trailing edges of
- * the cell group.
+ * The grid indices of the leading and trailing edges of this cell group for the
+ * appropriate axis.
* span
* properties of this Group and the supplied parameter are pairwise equal; false otherwise.
*
* @param that the object to compare this group with.
@@ -1898,9 +2127,6 @@ public class GridLayout extends ViewGroup {
}
}
- // Alignments
-
-
/**
* Alignments specify where a view should be placed within a cell group and
* what size it should be.
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index b3520da973eac..9c5562779ecee 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2522,10 +2522,10 @@