Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridLayout’s rowOrderPreserved and columnOrderPreserved

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.

like image 820
user1409534 Avatar asked Jun 14 '14 15:06

user1409534


1 Answers

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

like image 133
Alex Avatar answered Sep 17 '22 01:09

Alex