From 7fd948756947506db62a2bafca2ed45ff53ac0a0 Mon Sep 17 00:00:00 2001 From: Philip Milne Date: Tue, 7 Jun 2011 20:14:17 -0700 Subject: Fix for baseline alignment in LinearLayout compatibiity mode. Change-Id: Iaa194537c1bc493172fab89624279fe5cbfa1f70 --- .../src/com/android/test/layout/AlignmentTest.java | 18 +++++++++++------- .../src/com/android/test/layout/GridLayoutTest.java | 1 - .../src/com/android/test/layout/LinearLayoutTest.java | 5 ++--- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'tests/GridLayoutTest') diff --git a/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java b/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java index c6f390e..505c83d 100755 --- a/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java +++ b/tests/GridLayoutTest/src/com/android/test/layout/AlignmentTest.java @@ -31,10 +31,10 @@ import static android.widget.GridLayout.*; public class AlignmentTest extends Activity { - public static final String[] HORIZONTAL_NAMES = new String[]{"LEFT", "center", "east", "fill"}; - public static final Alignment[] HORIZONTAL_ALIGNMENTS = new Alignment[]{LEFT, CENTER, RIGHT, FILL}; - public static final String[] VERTICAL_NAMES = new String[]{"north", "center", "baseline", "south", "fill"}; - public static final Alignment[] VERTICAL_ALIGNMENTS = new Alignment[]{TOP, CENTER, BASELINE, BOTTOM, FILL}; + public static final String[] HORIZONTAL_NAMES = {"LEFT", "center", "east", "fill"}; + public static final Alignment[] HORIZONTAL_ALIGNMENTS = {LEFT, CENTER, RIGHT, FILL}; + public static final String[] VERTICAL_NAMES = {"north", "center", "baseline", "south", "fill"}; + public static final Alignment[] VERTICAL_ALIGNMENTS = {TOP, CENTER, BASELINE, BOTTOM, FILL}; private static Context CONTEXT; public static interface ViewFactory { @@ -72,7 +72,8 @@ public class AlignmentTest extends Activity { } }; - public static final ViewFactory[] FACTORIES = new ViewFactory[]{BUTTON_FACTORY, LABEL_FACTORY, TEXT_FIELD_FACTORY}; + public static final ViewFactory[] FACTORIES = + {BUTTON_FACTORY, LABEL_FACTORY, TEXT_FIELD_FACTORY}; public static ViewGroup create(Context context1) { CONTEXT = context1; @@ -86,7 +87,9 @@ public class AlignmentTest extends Activity { Group rowGroup = new Group(i, va); Group colGroup = new Group(j, ha); LayoutParams layoutParams = new LayoutParams(rowGroup, colGroup); - container.addView(FACTORIES[(i + j) % FACTORIES.length].create(VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20), layoutParams); + String name = VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j]; + ViewFactory factory = FACTORIES[(i + j) % FACTORIES.length]; + container.addView(factory.create(name, 20), layoutParams); } } @@ -105,7 +108,8 @@ public class AlignmentTest extends Activity { GridLayout p = (GridLayout) v.getParent(); p.layout(0, 0, 1000 + (i % 2), 500 + (i % 2)); } - System.out.println("Time: " + (float) (System.currentTimeMillis() - start) / N * 1000 + "mics"); + float time = (float) (System.currentTimeMillis() - start) / N * 1000; + System.out.println("Time: " + time + "mics"); } protected void onCreate(Bundle savedInstanceState) { diff --git a/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java index b4451e8..2eecb8a 100644 --- a/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java +++ b/tests/GridLayoutTest/src/com/android/test/layout/GridLayoutTest.java @@ -37,7 +37,6 @@ public class GridLayoutTest extends AbstractLayoutTest { GridLayout.Group colGroup = new GridLayout.Group(UNDEFINED, null); GridLayout.LayoutParams lp = new GridLayout.LayoutParams(rowGroup, colGroup); lp.setGravity(va | ha); -// View v = create(VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20); View v = create(context, VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20); container.addView(v, lp); } diff --git a/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java b/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java index fbd1239..c7f4665 100644 --- a/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java +++ b/tests/GridLayoutTest/src/com/android/test/layout/LinearLayoutTest.java @@ -22,20 +22,19 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import static android.widget.LinearLayout.*; +import static android.widget.LinearLayout.LayoutParams.*; public class LinearLayoutTest extends AbstractLayoutTest { public ViewGroup create(Context context) { LinearLayout container = new LinearLayout(context); container.setOrientation(LinearLayout.VERTICAL); -// container.setUseDefaultMargins(true); for (int i = 0; i < VERTICAL_ALIGNMENTS.length; i++) { int va = VERTICAL_ALIGNMENTS[i]; for (int j = 0; j < HORIZONTAL_ALIGNMENTS.length; j++) { int ha = HORIZONTAL_ALIGNMENTS[j]; - LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + LayoutParams lp = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT); lp.gravity = va | ha; -// View v = create(VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20); View v = create(context, VERTICAL_NAMES[i] + "-" + HORIZONTAL_NAMES[j], 20); container.addView(v, lp); } -- cgit v1.1