chapter 7f(layouts)

10
Android development A N D R O I D L A Y O U T S

Upload: cshashank1992

Post on 05-May-2017

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 7f(Layouts)

Android development

A N D R O I DL A Y O U T S

Page 2: Chapter 7f(Layouts)

GridLayout• GridLayout lays out views in a two-dimensional grid

pattern, that is, in a series of rows and columns. • The intersection of row and column is known as a

grid cell, and it is the place where child views are placed.

• It is easier to use GridLayout when compared to TableLayout.

• Without specifying intermediate views, we can flexibly place the views randomly in the grid by specifying their row and column positions

Page 3: Chapter 7f(Layouts)

Specifying Row and Column Position

• The two attributes that are used to specify the row and column position of the grid cell for inserting views are android:layout_row and android:layout_column.

• Together, they specify the exact location of the grid cell for placing the view. For example, the following statements place the view at the first row and column position of the grid:

android:layout_row="0"android:layout_column="0"

Page 4: Chapter 7f(Layouts)

The Code<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:rowCount="2" android:columnCount="2" > <Button android:id="@+id/btn1" android:text="Button1" /> <Button android:id="@+id/btn2" android:text="Button2" />

Page 5: Chapter 7f(Layouts)

The Code<Button android:id="@+id/btn3" android:text="Button3" /> <Button android:id="@+id/btn4" android:text="Button4" /></GridLayout>

Page 6: Chapter 7f(Layouts)
Page 7: Chapter 7f(Layouts)

Creating Space Between Components

• For inserting spaces, a spacing view called Space is used. That is, to insert spaces, the Space view is inserted as a child view. For example, the following statements insert a space at the second row in the GridLayout. The width and height of the blank space are 50dp and 10dp:

• <Space android:layout_row="1" android:layout_column="0" android:layout_width="50dp" android:layout_height="10dp"

android:layout_columnSpan=“2”/>

Page 8: Chapter 7f(Layouts)

The Code<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:rowCount=“3" android:columnCount=“2" > <Button android:id="@+id/btn1" android:text="Button1" /> <Button android:id="@+id/btn2" android:text="Button2" />

Page 9: Chapter 7f(Layouts)

The Code<Space android:layout_row="1" android:layout_column="0" android:layout_width="50dp" android:layout_height="10dp" android:layout_columnSpan="2" /> <Button android:layout_row="2" android:layout_column="0" android:id="@+id/btn3" android:text="Button3" /> <Button android:id="@+id/btn4" android:text="Button4" /></GridLayout>

Page 10: Chapter 7f(Layouts)