GridLayout’s rowOrderPreserved and columnOrderPreserved
Asked Answered
M

1

10

Can someone please explain what GridLayout’s rowOrderPreserved and columnOrderPreserved mean?

I don't understand the docs. What is the difference between setting the value to true or false. An illustration wil be very helpful.

Monoatomic answered 14/6, 2014 at 15:23 Comment(0)
V
4

Consider the following piece of code with GridLayout:

<GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:useDefaultMargins="true"
    android:alignmentMode="alignBounds"
    android:columnOrderPreserved="true"
    android:columnCount="4"
    >

    <TextView
        android:text="Email setup"
        android:textSize="32dip"
        android:layout_columnSpan="4"
        android:layout_gravity="center_horizontal"
        />

    <TextView
        android:text="Email address:"
        android:layout_gravity="left"
        />

    <EditText
        android:ems="10"
        />

    <TextView
        android:text="Password:"
        android:layout_column="0"
        android:layout_gravity="right"
        />

    <EditText
        android:ems="8"
        />



    <Button
        android:text="Next"
        android:layout_row="4"
        android:layout_column="3"
        />
</GridLayout>

This xml generates a view as follows in which the 'Next'-button is outside of the screen:

enter image description here

This is because the first EditText element defines the width of the second column. When defining the 'Next' button in the fourth column, it has to be right of the second column.

Now, changing the attribute columnOrderPreserved to false gives android the liberty to place the horizontal column boundaries in whatever order best fits the given constraints. (See the documentation) The result is as in this image:

enter image description here

Vally answered 23/11, 2016 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.