Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b559976a authored by Philip Milne's avatar Philip Milne
Browse files

Remove call to setPadding() in setUseDefaultMargins().

It is not possible for teh user to override the assigned padding values
because the XML attributes are processed in the opposite order.

Also, make the XML and Java examples grid3.xml and Activity2.java
consistent in preparation for a move to API demos.

Change-Id: I47334f9f5a46a8a528067d88350dd70eaa38ff33
parent b4918773
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -395,10 +395,6 @@ public class GridLayout extends ViewGroup {
     */
     */
    public void setUseDefaultMargins(boolean useDefaultMargins) {
    public void setUseDefaultMargins(boolean useDefaultMargins) {
        mUseDefaultMargins = useDefaultMargins;
        mUseDefaultMargins = useDefaultMargins;
        if (useDefaultMargins) {
            int padding = mDefaultGap;
            setPadding(padding, padding, padding, padding);
        }
        requestLayout();
        requestLayout();
    }
    }


@@ -740,6 +736,10 @@ public class GridLayout extends ViewGroup {
        graphics.drawLine(dx + x1, dy + y1, dx + x2, dy + y2, paint);
        graphics.drawLine(dx + x1, dy + y1, dx + x2, dy + y2, paint);
    }
    }


    private static void drawRect(Canvas canvas, int x1, int y1, int x2, int y2, Paint paint) {
        canvas.drawRect(x1, y1, x2 - 1, y2 - 1, paint);
    }

    @Override
    @Override
    protected void onDraw(Canvas canvas) {
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        super.onDraw(canvas);
@@ -772,14 +772,14 @@ public class GridLayout extends ViewGroup {
            paint.setColor(Color.BLUE);
            paint.setColor(Color.BLUE);
            for (int i = 0; i < getChildCount(); i++) {
            for (int i = 0; i < getChildCount(); i++) {
                View c = getChildAt(i);
                View c = getChildAt(i);
                canvas.drawRect(c.getLeft(), c.getTop(), c.getRight(), c.getBottom(), paint);
                drawRect(canvas, c.getLeft(), c.getTop(), c.getRight(), c.getBottom(), paint);
            }
            }


            // Draw margins
            // Draw margins
            paint.setColor(Color.MAGENTA);
            paint.setColor(Color.MAGENTA);
            for (int i = 0; i < getChildCount(); i++) {
            for (int i = 0; i < getChildCount(); i++) {
                View c = getChildAt(i);
                View c = getChildAt(i);
                canvas.drawRect(
                drawRect(canvas,
                        c.getLeft() - getMargin1(c, true, true),
                        c.getLeft() - getMargin1(c, true, true),
                        c.getTop() - getMargin1(c, false, true),
                        c.getTop() - getMargin1(c, false, true),
                        c.getRight() + getMargin1(c, true, false),
                        c.getRight() + getMargin1(c, true, false),
+5 −4
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@


        android:useDefaultMargins="true"
        android:useDefaultMargins="true"
        android:alignmentMode="alignBounds"
        android:alignmentMode="alignBounds"
        android:rowOrderPreserved="false"


        android:columnCount="4"
        android:columnCount="4"
        >
        >
@@ -49,7 +50,7 @@
            />
            />


    <EditText
    <EditText
            android:layout_width="64dip"
            android:ems="10"
            />
            />


    <TextView
    <TextView
@@ -60,13 +61,13 @@
            />
            />


    <EditText
    <EditText
            android:layout_width="32dip"
            android:ems="8"
            />
            />


    <Space
    <Space
            android:layout_row="4"
            android:layout_row="2"
            android:layout_rowSpan="3"
            android:layout_column="2"
            android:layout_column="2"
            android:layout_margin="0dip"
            android:layout_gravity="fill"
            android:layout_gravity="fill"
            />
            />


+4 −12
Original line number Original line Diff line number Diff line
@@ -38,7 +38,6 @@ public class Activity2 extends Activity {
        p.setUseDefaultMargins(true);
        p.setUseDefaultMargins(true);
        p.setAlignmentMode(ALIGN_BOUNDS);
        p.setAlignmentMode(ALIGN_BOUNDS);
        p.setRowOrderPreserved(false);
        p.setRowOrderPreserved(false);
        p.setPadding(0, 0, 0, 0);


        Spec row1 = spec(0);
        Spec row1 = spec(0);
        Spec row2 = spec(1);
        Spec row2 = spec(1);
@@ -75,12 +74,9 @@ public class Activity2 extends Activity {
        }
        }
        {
        {
            EditText c = new EditText(context);
            EditText c = new EditText(context);
            c.setEms(10);
            c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
            c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
            {
            p.addView(c, new LayoutParams(row3, col2));
                LayoutParams lp = new LayoutParams(row3, col2);
                lp.width = (int) c.getPaint().measureText("Frederick.W.Flintstone");
                p.addView(c, lp);
            }
        }
        }
        {
        {
            TextView c = new TextView(context);
            TextView c = new TextView(context);
@@ -89,17 +85,13 @@ public class Activity2 extends Activity {
        }
        }
        {
        {
            TextView c = new EditText(context);
            TextView c = new EditText(context);
            c.setEms(8);
            c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD);
            c.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD);
            {
            p.addView(c, new LayoutParams(row4, col2));
                LayoutParams lp = new LayoutParams(row4, col2);
                lp.width = (int) c.getPaint().measureText("************");
                p.addView(c, lp);
            }
        }
        }
        {
        {
            Space c = new Space(context);
            Space c = new Space(context);
            LayoutParams lp = new LayoutParams(row5, col3);
            LayoutParams lp = new LayoutParams(row5, col3);
            lp.setMargins(0, 0, 0, 0);
            p.addView(c, lp);
            p.addView(c, lp);
        }
        }
        {
        {