summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.txt9
-rw-r--r--core/java/android/widget/GridLayout.java337
-rwxr-xr-xcore/res/res/values/attrs.xml14
-rw-r--r--tests/GridLayoutTest/res/layout/grid3.xml15
-rw-r--r--tests/GridLayoutTest/src/com/android/test/layout/Activity2.java29
5 files changed, 181 insertions, 223 deletions
diff --git a/api/current.txt b/api/current.txt
index 2514efd..31a4b9f 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -607,7 +607,7 @@ 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_columnFlexibility = 16843644; // 0x101037c
+ field public static final deprecated int layout_columnFlexibility = 16843644; // 0x101037c
field public static final int layout_columnSpan = 16843643; // 0x101037b
field public static final int layout_gravity = 16842931; // 0x10100b3
field public static final int layout_height = 16842997; // 0x10100f5
@@ -617,7 +617,7 @@ package android {
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 = 16843640; // 0x1010378
- field public static final int layout_rowFlexibility = 16843642; // 0x101037a
+ field public static final deprecated int layout_rowFlexibility = 16843642; // 0x101037a
field public static final int layout_rowSpan = 16843641; // 0x1010379
field public static final int layout_scale = 16843155; // 0x1010193
field public static final int layout_span = 16843085; // 0x101014d
@@ -25433,15 +25433,14 @@ package android.widget {
method public void setRowCount(int);
method public void setRowOrderPreserved(boolean);
method public void setUseDefaultMargins(boolean);
- method public static android.widget.GridLayout.Spec spec(int, int, android.widget.GridLayout.Alignment, int);
- method public static android.widget.GridLayout.Spec spec(int, android.widget.GridLayout.Alignment, int);
method public static android.widget.GridLayout.Spec spec(int, int, android.widget.GridLayout.Alignment);
method public static android.widget.GridLayout.Spec spec(int, android.widget.GridLayout.Alignment);
+ method public static android.widget.GridLayout.Spec spec(int, int);
+ method public static android.widget.GridLayout.Spec spec(int);
field public static final int ALIGN_BOUNDS = 0; // 0x0
field public static final int ALIGN_MARGINS = 1; // 0x1
field public static final android.widget.GridLayout.Alignment BASELINE;
field public static final android.widget.GridLayout.Alignment BOTTOM;
- field public static final int CAN_STRETCH = 2; // 0x2
field public static final android.widget.GridLayout.Alignment CENTER;
field public static final android.widget.GridLayout.Alignment FILL;
field public static final int HORIZONTAL = 0; // 0x0
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index 3bd7fab..f999960 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -21,7 +21,6 @@ import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
-import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
@@ -38,6 +37,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static android.view.Gravity.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
@@ -167,7 +167,7 @@ public class GridLayout extends ViewGroup {
// Misc constants
private static final String TAG = GridLayout.class.getName();
- static boolean DEBUG = false;
+ private static boolean DEBUG = false;
private static final int PRF = 1;
// Defaults
@@ -198,7 +198,8 @@ public class GridLayout extends ViewGroup {
private int mOrientation = DEFAULT_ORIENTATION;
private boolean mUseDefaultMargins = DEFAULT_USE_DEFAULT_MARGINS;
private int mAlignmentMode = DEFAULT_ALIGNMENT_MODE;
- private int mDefaultGravity = Gravity.NO_GRAVITY;
+ private Alignment mColumnAlignment = LEFT;
+ private Alignment mRowAlignment = BASELINE;
private int mDefaultGap;
// Constructors
@@ -216,9 +217,9 @@ public class GridLayout extends ViewGroup {
try {
setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT));
setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT));
- mOrientation = a.getInt(ORIENTATION, DEFAULT_ORIENTATION);
- mUseDefaultMargins = a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS);
- mAlignmentMode = a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE);
+ setOrientation(a.getInt(ORIENTATION, DEFAULT_ORIENTATION));
+ setUseDefaultMargins(a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS));
+ setAlignmentMode(a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE));
setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
} finally {
@@ -514,6 +515,8 @@ public class GridLayout extends ViewGroup {
requestLayout();
}
+ // Static utility methods
+
private static int max2(int[] a, int valueIfEmpty) {
int result = valueIfEmpty;
for (int i = 0, N = a.length; i < N; i++) {
@@ -537,6 +540,24 @@ public class GridLayout extends ViewGroup {
return result;
}
+ private static Alignment getAlignment(int gravity, boolean horizontal) {
+ int mask = horizontal ? HORIZONTAL_GRAVITY_MASK : VERTICAL_GRAVITY_MASK;
+ int shift = horizontal ? AXIS_X_SHIFT : AXIS_Y_SHIFT;
+ int flags = (gravity & mask) >> shift;
+ switch (flags) {
+ case (AXIS_SPECIFIED | AXIS_PULL_BEFORE):
+ return LEADING;
+ case (AXIS_SPECIFIED | AXIS_PULL_AFTER):
+ return TRAILING;
+ case (AXIS_SPECIFIED | AXIS_PULL_BEFORE | AXIS_PULL_AFTER):
+ return FILL;
+ case AXIS_SPECIFIED:
+ return CENTER;
+ default:
+ return UNDEFINED_ALIGNMENT;
+ }
+ }
+
private int getDefaultMargin(View c, boolean horizontal, boolean leading) {
return mDefaultGap / 2;
}
@@ -678,7 +699,7 @@ public class GridLayout extends ViewGroup {
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
- return new LayoutParams(getContext(), attrs, mDefaultGravity);
+ return new LayoutParams(getContext(), attrs);
}
@Override
@@ -833,6 +854,9 @@ public class GridLayout extends ViewGroup {
}
private int getMeasurementIncludingMargin(View c, boolean horizontal) {
+ if (isGone(c)) {
+ return 0;
+ }
int result = getMeasurement(c, horizontal);
if (mAlignmentMode == ALIGN_MARGINS) {
return result + getTotalMargin(c, horizontal);
@@ -846,6 +870,11 @@ public class GridLayout extends ViewGroup {
invalidateValues();
}
+ private Alignment getAlignment(Alignment alignment, boolean horizontal) {
+ return (alignment != UNDEFINED_ALIGNMENT) ? alignment :
+ (horizontal ? mColumnAlignment : mRowAlignment);
+ }
+
// Layout container
/**
@@ -895,8 +924,8 @@ public class GridLayout extends ViewGroup {
int pWidth = getMeasurement(c, true);
int pHeight = getMeasurement(c, false);
- Alignment hAlign = columnSpec.alignment;
- Alignment vAlign = rowSpec.alignment;
+ Alignment hAlign = getAlignment(columnSpec.alignment, true);
+ Alignment vAlign = getAlignment(rowSpec.alignment, false);
int dx, dy;
@@ -1035,14 +1064,10 @@ public class GridLayout extends ViewGroup {
Assoc<Spec, Bounds> assoc = Assoc.of(Spec.class, Bounds.class);
for (int i = 0, N = getChildCount(); i < N; i++) {
View c = getChildAt(i);
- if (isGone(c)) {
- assoc.put(Spec.GONE, Bounds.GONE);
- } else {
- LayoutParams lp = getLayoutParams(c);
- Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
- Bounds bounds = spec.alignment.getBounds();
- assoc.put(spec, bounds);
- }
+ LayoutParams lp = getLayoutParams(c);
+ Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
+ Bounds bounds = getAlignment(spec.alignment, horizontal).getBounds();
+ assoc.put(spec, bounds);
}
return assoc.pack();
}
@@ -1054,7 +1079,6 @@ public class GridLayout extends ViewGroup {
}
for (int i = 0, N = getChildCount(); i < N; i++) {
View c = getChildAt(i);
- if (isGone(c)) continue;
LayoutParams lp = getLayoutParams(c);
Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
groupBounds.getValue(i).include(c, spec, GridLayout.this, this);
@@ -1094,11 +1118,8 @@ public class GridLayout extends ViewGroup {
for (int i = 0; i < bounds.length; i++) {
int size = bounds[i].size(min);
MutableInt valueHolder = links.getValue(i);
- if (min) {
- valueHolder.value = max(valueHolder.value, size);
- } else {
- valueHolder.value = -max(-valueHolder.value, size);
- }
+ // this effectively takes the max() of the minima and the min() of the maxima
+ valueHolder.value = max(valueHolder.value, min ? size : -size);
}
}
@@ -1397,7 +1418,7 @@ public class GridLayout extends ViewGroup {
}
if (!changed) {
if (DEBUG) {
- Log.d(TAG, axis + " iteration completed in " + (1 + i) + " steps of " + N);
+ Log.v(TAG, axis + " iteration completed in " + (1 + i) + " steps of " + N);
}
return;
}
@@ -1654,14 +1675,6 @@ public class GridLayout extends ViewGroup {
private static final int DEFAULT_COLUMN = UNDEFINED;
private static final Interval DEFAULT_SPAN = new Interval(UNDEFINED, UNDEFINED + 1);
private static final int DEFAULT_SPAN_SIZE = DEFAULT_SPAN.size();
- private static final Alignment DEFAULT_COLUMN_ALIGNMENT = LEFT;
- private static final Alignment DEFAULT_ROW_ALIGNMENT = BASELINE;
-
- // Misc
-
- private static final Rect CONTAINER_BOUNDS = new Rect(0, 0, 2, 2);
- private static final Alignment[] COLUMN_ALIGNMENTS = { LEFT, CENTER, RIGHT };
- private static final Alignment[] ROW_ALIGNMENTS = { TOP, CENTER, BOTTOM };
// TypedArray indices
@@ -1728,8 +1741,7 @@ public class GridLayout extends ViewGroup {
* Constructs a new LayoutParams with default values as defined in {@link LayoutParams}.
*/
public LayoutParams() {
- this(new Spec(DEFAULT_SPAN, DEFAULT_ROW_ALIGNMENT, Spec.DEFAULT_FLEXIBILITY),
- new Spec(DEFAULT_SPAN, DEFAULT_COLUMN_ALIGNMENT, Spec.DEFAULT_FLEXIBILITY));
+ this(spec(UNDEFINED), spec(UNDEFINED));
}
// Copying constructors
@@ -1753,18 +1765,12 @@ public class GridLayout extends ViewGroup {
*/
public LayoutParams(LayoutParams that) {
super(that);
- this.columnSpec = new Spec(that.columnSpec);
this.rowSpec = new Spec(that.rowSpec);
+ this.columnSpec = new Spec(that.columnSpec);
}
// AttributeSet constructors
- private LayoutParams(Context context, AttributeSet attrs, int defaultGravity) {
- super(context, attrs);
- reInitSuper(context, attrs);
- init(context, attrs, defaultGravity);
- }
-
/**
* {@inheritDoc}
*
@@ -1772,27 +1778,13 @@ public class GridLayout extends ViewGroup {
* defined in {@link LayoutParams}.
*/
public LayoutParams(Context context, AttributeSet attrs) {
- this(context, attrs, Gravity.NO_GRAVITY);
+ super(context, attrs);
+ reInitSuper(context, attrs);
+ init(context, attrs);
}
// Implementation
- private static boolean definesVertical(int gravity) {
- return gravity > 0 && (gravity & Gravity.VERTICAL_GRAVITY_MASK) != 0;
- }
-
- private static boolean definesHorizontal(int gravity) {
- return gravity > 0 && (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) != 0;
- }
-
- private static <T> T getAlignment(T[] alignments, T fill, int min, int max,
- boolean isUndefined, T defaultValue) {
- if (isUndefined) {
- return defaultValue;
- }
- return min != max ? fill : alignments[min];
- }
-
// Reinitialise the margins using a different default policy than MarginLayoutParams.
// Here we use the value UNDEFINED (as distinct from zero) to represent the undefined state
// so that a layout manager default can be accessed post set up. We need this as, at the
@@ -1817,44 +1809,20 @@ public class GridLayout extends ViewGroup {
}
}
- // Gravity. For conversion from the static the integers defined in the Gravity class,
- // use Gravity.apply() to apply gravity to a view of zero size and see where it ends up.
- private static Alignment getColAlignment(int gravity, int width) {
- Rect r = new Rect(0, 0, 0, 0);
- Gravity.apply(gravity, 0, 0, CONTAINER_BOUNDS, r);
-
- boolean fill = (width == MATCH_PARENT);
- Alignment defaultAlignment = fill ? FILL : DEFAULT_COLUMN_ALIGNMENT;
- return getAlignment(COLUMN_ALIGNMENTS, FILL, r.left, r.right,
- !definesHorizontal(gravity), defaultAlignment);
- }
-
- private static Alignment getRowAlignment(int gravity, int height) {
- Rect r = new Rect(0, 0, 0, 0);
- Gravity.apply(gravity, 0, 0, CONTAINER_BOUNDS, r);
-
- boolean fill = (height == MATCH_PARENT);
- Alignment defaultAlignment = fill ? FILL : DEFAULT_ROW_ALIGNMENT;
- return getAlignment(ROW_ALIGNMENTS, FILL, r.top, r.bottom,
- !definesVertical(gravity), defaultAlignment);
- }
-
- private void init(Context context, AttributeSet attrs, int defaultGravity) {
+ private void init(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridLayout_Layout);
try {
- int gravity = a.getInt(GRAVITY, defaultGravity);
+ int gravity = a.getInt(GRAVITY, Gravity.NO_GRAVITY);
int column = a.getInt(COLUMN, DEFAULT_COLUMN);
- int columnSpan = a.getInt(COLUMN_SPAN, DEFAULT_SPAN_SIZE);
- Interval hSpan = new Interval(column, column + columnSpan);
- int hFlexibility = a.getInt(COLUMN_FLEXIBILITY, Spec.DEFAULT_FLEXIBILITY);
- this.columnSpec = new Spec(hSpan, getColAlignment(gravity, width), hFlexibility);
+ int colSpan = a.getInt(COLUMN_SPAN, DEFAULT_SPAN_SIZE);
+ int hFlexibility = a.getInt(COLUMN_FLEXIBILITY, Spec.UNDEFINED_FLEXIBILITY);
+ this.columnSpec = spec(column, colSpan, getAlignment(gravity, true), hFlexibility);
int row = a.getInt(ROW, DEFAULT_ROW);
int rowSpan = a.getInt(ROW_SPAN, DEFAULT_SPAN_SIZE);
- Interval vSpan = new Interval(row, row + rowSpan);
- int vFlexibility = a.getInt(ROW_FLEXIBILITY, Spec.DEFAULT_FLEXIBILITY);
- this.rowSpec = new Spec(vSpan, getRowAlignment(gravity, height), vFlexibility);
+ int vFlexibility = a.getInt(ROW_FLEXIBILITY, Spec.UNDEFINED_FLEXIBILITY);
+ this.rowSpec = spec(row, rowSpan, getAlignment(gravity, false), vFlexibility);
} finally {
a.recycle();
}
@@ -1869,8 +1837,8 @@ public class GridLayout extends ViewGroup {
* @attr ref android.R.styleable#GridLayout_Layout_layout_gravity
*/
public void setGravity(int gravity) {
- columnSpec = columnSpec.copyWriteAlignment(getColAlignment(gravity, width));
- rowSpec = rowSpec.copyWriteAlignment(getRowAlignment(gravity, height));
+ rowSpec = rowSpec.copyWriteAlignment(getAlignment(gravity, false));
+ columnSpec = columnSpec.copyWriteAlignment(getAlignment(gravity, true));
}
@Override
@@ -2045,7 +2013,7 @@ public class GridLayout extends ViewGroup {
public int before;
public int after;
- public int flexibility;
+ public int flexibility; // we're flexible iff all included specs are flexible
private Bounds() {
reset();
@@ -2054,7 +2022,7 @@ public class GridLayout extends ViewGroup {
protected void reset() {
before = Integer.MIN_VALUE;
after = Integer.MIN_VALUE;
- flexibility = UNDEFINED_FLEXIBILITY;
+ flexibility = CAN_STRETCH; // from the above, we're flexible when empty
}
protected void include(int before, int after) {
@@ -2064,10 +2032,7 @@ public class GridLayout extends ViewGroup {
protected int size(boolean min) {
if (!min) {
- // Note in the usual case, components don't define anything
- // leaving their flexibility is undefined and their stretchability
- // defined as if the CAN_STRETCH flag was false.
- if (canStretch(flexibility) && !isUndefined(flexibility)) {
+ if (canStretch(flexibility)) {
return MAX_SIZE;
}
}
@@ -2078,11 +2043,12 @@ public class GridLayout extends ViewGroup {
return before - alignment.getAlignmentValue(c, size);
}
- protected void include(View c, Spec spec, GridLayout gridLayout, Axis axis) {
- this.flexibility &= spec.flexibility;
+ protected final void include(View c, Spec spec, GridLayout gridLayout, Axis axis) {
+ this.flexibility &= spec.getFlexibility();
int size = gridLayout.getMeasurementIncludingMargin(c, axis.horizontal);
// todo test this works correctly when the returned value is UNDEFINED
- int before = spec.alignment.getAlignmentValue(c, size);
+ Alignment alignment = gridLayout.getAlignment(spec.alignment, axis.horizontal);
+ int before = alignment.getAlignmentValue(c, size);
include(before, size - before);
}
@@ -2107,8 +2073,6 @@ public class GridLayout extends ViewGroup {
* {@code x} such that {@code min <= x < max}.
*/
static class Interval {
- private static final Interval GONE = new Interval(UNDEFINED, UNDEFINED);
-
/**
* The minimum value.
*/
@@ -2186,40 +2150,38 @@ public class GridLayout extends ViewGroup {
}
}
- /**
- * A spec defines either the horizontal or vertical characteristics of a group of
- * cells.
- */
+ /**
+ * A Spec defines the horizontal or vertical characteristics of a group of
+ * cells. Each spec. defines the <em>grid indices</em>, <em>alignment</em> and
+ * <em>flexibility</em> along the appropriate axis.
+ * <p>
+ * The <em>grid indices</em> are the leading and trailing edges of this cell group.
+ * See {@link GridLayout} for a description of the conventions used by GridLayout
+ * for grid indices.
+ * <p>
+ * The <em>alignment</em> property specifies how cells should be aligned in this group.
+ * For row groups, this specifies the vertical alignment.
+ * For column groups, this specifies the horizontal alignment.
+ */
public static class Spec {
- private static final int DEFAULT_FLEXIBILITY = UNDEFINED_FLEXIBILITY;
-
- private static final Spec GONE = new Spec(Interval.GONE, Alignment.GONE);
+ private static final int UNDEFINED_FLEXIBILITY = UNDEFINED;
- /**
- * The grid indices of the leading and trailing edges of this cell group for the
- * appropriate axis.
- * <p>
- * See {@link GridLayout} for a description of the conventions used by GridLayout
- * for grid indices.
- */
final Interval span;
- /**
- * Specifies how cells should be aligned in this group.
- * For row groups, this specifies the vertical alignment.
- * For column groups, this specifies the horizontal alignment.
- */
+
final Alignment alignment;
- /**
- * The flexibility field tells GridLayout how to derive minimum and maximum size
- * values for a component. Specifications are made with respect to a child's
- * 'measured size'. A child's measured size is, in turn, controlled by its
- * height and width layout parameters which either specify a size or, in
- * the case of {@link LayoutParams#WRAP_CONTENT WRAP_CONTENT}, defer to
- * the computed size of the component.
- *
- * @see GridLayout#CAN_STRETCH
- */
+ /**
+ * The <em>flexibility</em> property tells GridLayout how to derive minimum and maximum size
+ * values for a component. Specifications are made with respect to a child's
+ * 'measured size'. A child's measured size is, in turn, controlled by its
+ * height and width layout parameters which either specify a size or, in
+ * the case of {@link LayoutParams#WRAP_CONTENT WRAP_CONTENT}, defer to
+ * the computed size of the component.
+ * <p>
+ * A cell group is flexible only if <em>all</em> of its components are flexible.
+ * <p>
+ * By default, flexibility is {@link #INFLEXIBLE} only when alignment/gravity is undefined.
+ */
final int flexibility;
private Spec(Interval span, Alignment alignment, int flexibility) {
@@ -2229,7 +2191,7 @@ public class GridLayout extends ViewGroup {
}
private Spec(Interval span, Alignment alignment) {
- this(span, alignment, DEFAULT_FLEXIBILITY);
+ this(span, alignment, UNDEFINED_FLEXIBILITY);
}
/* Copying constructor */
@@ -2249,8 +2211,14 @@ public class GridLayout extends ViewGroup {
return new Spec(span, alignment, flexibility);
}
- private Spec copyWriteFlexibility(int flexibility) {
- return new Spec(span, alignment, flexibility);
+ private static int defaultFlexibility(Alignment alignment) {
+ return (alignment == UNDEFINED_ALIGNMENT) ? INFLEXIBLE : CAN_STRETCH;
+ }
+
+ int getFlexibility() {
+ return (flexibility != UNDEFINED_FLEXIBILITY) ?
+ flexibility :
+ defaultFlexibility(alignment);
}
/**
@@ -2293,34 +2261,23 @@ public class GridLayout extends ViewGroup {
}
/**
- * Return a Spec, {@code spec}, where:
- * <ul>
- * <li> {@code spec.span = [start, start + size]} </li>
- * <li> {@code spec.alignment = alignment} </li>
- * <li> {@code spec.flexibility = flexibility} </li>
- * </ul>
+ * @deprecated Please use {@link #spec(int, int, Alignment)} instead,
+ * all spec's that define alignments (gravity) are assumed to be able to stretch.
*
- * @param start the start
- * @param size the size
- * @param alignment the alignment
- * @param flexibility the flexibility
+ * @hide
*/
+ @Deprecated
public static Spec spec(int start, int size, Alignment alignment, int flexibility) {
return new Spec(start, size, alignment, flexibility);
}
/**
- * Return a Spec, {@code spec}, where:
- * <ul>
- * <li> {@code spec.span = [start, start + 1]} </li>
- * <li> {@code spec.alignment = alignment} </li>
- * <li> {@code spec.flexibility = flexibility} </li>
- * </ul>
+ * @deprecated Please use {@link #spec(int, Alignment)} instead,
+ * all spec's that define alignments (gravity) are assumed to be able to stretch.
*
- * @param start the start
- * @param alignment the alignment
- * @param flexibility the flexibility
+ * @hide
*/
+ @Deprecated
public static Spec spec(int start, Alignment alignment, int flexibility) {
return spec(start, 1, alignment, flexibility);
}
@@ -2337,7 +2294,7 @@ public class GridLayout extends ViewGroup {
* @param alignment the alignment
*/
public static Spec spec(int start, int size, Alignment alignment) {
- return spec(start, size, alignment, Spec.DEFAULT_FLEXIBILITY);
+ return spec(start, size, alignment, Spec.UNDEFINED_FLEXIBILITY);
}
/**
@@ -2355,6 +2312,31 @@ public class GridLayout extends ViewGroup {
}
/**
+ * Return a Spec, {@code spec}, where:
+ * <ul>
+ * <li> {@code spec.span = [start, start + size]} </li>
+ * </ul>
+ *
+ * @param start the start
+ * @param size the size
+ */
+ public static Spec spec(int start, int size) {
+ return spec(start, size, UNDEFINED_ALIGNMENT);
+ }
+
+ /**
+ * Return a Spec, {@code spec}, where:
+ * <ul>
+ * <li> {@code spec.span = [start, start + 1]} </li>
+ * </ul>
+ *
+ * @param start the start index
+ */
+ public static Spec spec(int start) {
+ return spec(start, 1);
+ }
+
+ /**
* Alignments specify where a view should be placed within a cell group and
* what size it should be.
* <p>
@@ -2376,13 +2358,6 @@ public class GridLayout extends ViewGroup {
* <p>
*/
public static abstract class Alignment {
- private static final Alignment GONE = new Alignment() {
- public int getAlignmentValue(View view, int viewSize) {
- assert false;
- return 0;
- }
- };
-
Alignment() {
}
@@ -2422,11 +2397,16 @@ public class GridLayout extends ViewGroup {
}
}
+ private static final Alignment UNDEFINED_ALIGNMENT = new Alignment() {
+ public int getAlignmentValue(View view, int viewSize) {
+ return UNDEFINED;
+ }
+ };
+
private static final Alignment LEADING = new Alignment() {
public int getAlignmentValue(View view, int viewSize) {
return 0;
}
-
};
private static final Alignment TRAILING = new Alignment() {
@@ -2542,38 +2522,17 @@ public class GridLayout extends ViewGroup {
return (flexibility & CAN_STRETCH) != 0;
}
- private static boolean isUndefined(int flexibility) {
- return (flexibility & UNDEFINED) != 0;
- }
-
- /**
- * Indicates that a view requests precisely the size specified by its layout parameters.
- *
- * @see Spec#flexibility
- */
- private static final int NONE = 0;
-
- /**
- * Indicates that a view's size should lie between its minimum and the size specified by
- * its layout parameters.
- *
- * @see Spec#flexibility
- */
- private static final int CAN_SHRINK = 1;
+ private static final int INFLEXIBLE = 0;
/**
* Indicates that a view's size should be greater than or equal to the size specified by
* its layout parameters.
*
- * @see Spec#flexibility
- */
- public static final int CAN_STRETCH = 2;
-
- /**
- * A default value for flexibility.
+ * @deprecated Please use {@link #spec(int, int, Alignment)} instead,
+ * all spec's that define alignment (gravity) are assumed to able to stretch.
*
- * @see Spec#flexibility
+ * @hide
*/
- private static final int UNDEFINED_FLEXIBILITY = UNDEFINED | CAN_SHRINK | CAN_STRETCH;
-
+ @Deprecated
+ public static final int CAN_STRETCH = 2;
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 7d7aea9..07e2043 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3359,18 +3359,16 @@
The default is LEFT | BASELINE.
See {@link android.widget.GridLayout.LayoutParams#setGravity(int)}. -->
<attr name="layout_gravity" />
- <!-- A value specifying how much deficit or excess width this component can accomodate.
- The default is FIXED. -->
+ <!-- {@deprecated To make a column group lexible, ensure that every component in the
+ group defines a horizontal gravity.} -->
<attr name="layout_columnFlexibility" >
- <!-- If possible, width should be greater than or equal to the specified width.
- See {@link android.widget.GridLayout#CAN_STRETCH}. -->
+ <enum name="inflexible" value="0" />
<enum name="canStretch" value="2" />
</attr>
- <!-- A value specifying how much deficit or excess height this component can accomodate.
- The default is FIXED. -->
+ <!-- {@deprecated To make a row group flexible, ensure that every component in the
+ group defines a vertical gravity.} -->
<attr name="layout_rowFlexibility" >
- <!-- If possible, height should be greater than or equal to the specified height.
- See {@link android.widget.GridLayout#CAN_STRETCH}. -->
+ <enum name="inflexible" value="0" />
<enum name="canStretch" value="2" />
</attr>
</declare-styleable>
diff --git a/tests/GridLayoutTest/res/layout/grid3.xml b/tests/GridLayoutTest/res/layout/grid3.xml
index 3c2db54..2eca384 100644
--- a/tests/GridLayoutTest/res/layout/grid3.xml
+++ b/tests/GridLayoutTest/res/layout/grid3.xml
@@ -27,8 +27,8 @@
>
<TextView
- android:text="Email account"
- android:textSize="48dip"
+ android:text="Email setup"
+ android:textSize="32dip"
android:layout_columnSpan="4"
android:layout_gravity="center_horizontal"
@@ -36,7 +36,7 @@
<TextView
android:text="You can configure email in just a few steps:"
- android:textSize="20dip"
+ android:textSize="16dip"
android:layout_columnSpan="4"
android:layout_gravity="left"
@@ -49,7 +49,7 @@
/>
<EditText
- android:layout_width="100dip"
+ android:layout_width="64dip"
/>
<TextView
@@ -60,14 +60,14 @@
/>
<EditText
- android:layout_width="50dip"
+ android:layout_width="32dip"
/>
<Space
android:layout_row="4"
android:layout_column="2"
- android:layout_rowFlexibility="canStretch"
- android:layout_columnFlexibility="canStretch"
+ android:layout_margin="0dip"
+ android:layout_gravity="fill"
/>
<Button
@@ -75,7 +75,6 @@
android:layout_row="5"
android:layout_column="3"
- android:layout_gravity="fill_horizontal"
/>
<Button
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
index 38a85a3..e1871ac 100644
--- a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
+++ b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
@@ -38,30 +38,31 @@ public class Activity2 extends Activity {
vg.setUseDefaultMargins(true);
vg.setAlignmentMode(ALIGN_BOUNDS);
- Spec row1 = spec(0, CENTER);
- Spec row2 = spec(1, CENTER);
+ Spec row1 = spec(0);
+ Spec row2 = spec(1);
Spec row3 = spec(2, BASELINE);
Spec row4 = spec(3, BASELINE);
- Spec row5 = spec(4, FILL, CAN_STRETCH);
- Spec row6 = spec(5, CENTER);
- Spec row7 = spec(6, CENTER);
+ Spec row5 = spec(4, FILL);
+ Spec row6 = spec(5);
+ Spec row7 = spec(6);
Spec col1a = spec(0, 4, CENTER);
Spec col1b = spec(0, 4, LEFT);
Spec col1c = spec(0, RIGHT);
Spec col2 = spec(1, LEFT);
- Spec col3 = spec(2, FILL, CAN_STRETCH);
- Spec col4 = spec(3, FILL);
+ Spec col3 = spec(2, FILL);
+ Spec col4a = spec(3);
+ Spec col4b = spec(3, FILL);
{
TextView v = new TextView(context);
- v.setTextSize(48);
+ v.setTextSize(32);
v.setText("Email setup");
vg.addView(v, new LayoutParams(row1, col1a));
}
{
TextView v = new TextView(context);
- v.setTextSize(20);
+ v.setTextSize(16);
v.setText("You can configure email in just a few steps:");
vg.addView(v, new LayoutParams(row2, col1b));
}
@@ -75,7 +76,7 @@ public class Activity2 extends Activity {
v.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
{
LayoutParams lp = new LayoutParams(row3, col2);
- lp.width = (int) v.getPaint().measureText("Frederick.W.Flintstone@bedrock.com ");
+ lp.width = (int) v.getPaint().measureText("Frederick.W.Flintstone");
vg.addView(v, lp);
}
}
@@ -95,17 +96,19 @@ public class Activity2 extends Activity {
}
{
Space v = new Space(context);
- vg.addView(v, new LayoutParams(row5, col3));
+ LayoutParams lp = new LayoutParams(row5, col3);
+ lp.setMargins(0, 0, 0, 0);
+ vg.addView(v, lp);
}
{
Button v = new Button(context);
v.setText("Manual setup");
- vg.addView(v, new LayoutParams(row6, col4));
+ vg.addView(v, new LayoutParams(row6, col4a));
}
{
Button v = new Button(context);
v.setText("Next");
- vg.addView(v, new LayoutParams(row7, col4));
+ vg.addView(v, new LayoutParams(row7, col4b));
}
return vg;