Tuesday, 1 October 2013

Android GridLayout Example (New Feature in 4.0)

Here The Below Example shows How to create GridLayout in Android ?

GridLayout induced in Android 4.0 as New Feature.

LinearLayout and RelativeLayout are the most common layouts used in user
interface design in Android. For simple user interfaces they are a good choice but
when the user interface gets complicated, the use of nested LinearLayout tends
to increase. Nested layouts (of any type) can hurt performance, and furthermore
nested LinearLayout deeper than 10 may cause a crash in your application.
Thus, you should either avoid using too many nested LinearLayout blocks or
you should use RelativeLayout in order to decrease nested LinearLayout blocks.
Another drawback of these layouts for complicated user interfaces is the difficulty
in readability. It is difficult to maintain nested LinearLayout or RelativeLayout
layouts that have many views. It is a good choice to use GridLayout in these
cases. Too many nested LinearLayouts could be avoided by using GridLayout.
Furthermore, it is much easier to maintain GridLayout. Many of the user interfaces
that use LinearLayout, RelativeLayout, or TableLayout can be converted to
GridLayout where GridLayout will provide performance enhancements. One of
the major advantages of GridLayout over other layouts is that you can control the
alignment of a view in both horizontal and vertical axes.

Example GridLayout:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnCount="3"
    android:rowCount="3" >
    <Button android:text="1,1" />
    <Button android:text="1,2" />
    <Button android:text="1,3" />
    <Button android:text="2,1" />
    <Button android:text="2,2" />
    <Button android:text="2,3" />
    <Button android:text="3,1" />
    <Button android:text="3,2" />
    <Button android:text="3,3" />
</GridLayout>

Output Screen:








No comments:

Post a Comment

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of...