Android Full Tutorial

Only available on StudyMode
  • Topic: File system, Layout manager, Page orientation
  • Pages : 17 (2963 words )
  • Download(s) : 222
  • Published : September 28, 2012
Open Document
Text Preview
If you run your application and click your button you should see your dialog.

15. Layout Manager and ViewGroups
15.1. Available Layout Manager
A layout manager is a subclass of ViewGroup and is responsible for the layout of itself and its child Views. Android supports different default layout managers. As of Android 4.0 the most relevant layout manager are LinearLayout, FrameLayout, RelativeLayout and GridLayout. All layouts allow the developer to define attributes. Children can also define attributes which may be evaluated by their parent layout. AbsoluteLayoutLayout is deprecated and TableLayout can be implemented more effectively via GridLayout 15.2. LinearLayout

LinearLayout puts all its child elements into a single column or row depending on the android:orientation attribute. Possible values for this attribute are horizontal and vertical, horizontal is the default value. LinearLayout can be nested to achieve more complex layouts. 15.3. GridLayout

15.3.1. Overview
GridLayout was introduced with Android 4.0. This layout allows you to organize a view into a Grid. GridLayout separates its drawing area into: rows, columns, and cells. You can specify how many columns you want for define for each View in which row and column it should be placed and how many columns and rows it should use. If not specified GridLayout uses defaults, e.g. one column, one row and the position of a View depends on the order of the declaration of the Views. 15.3.2. Tutorial GridLayout

Create the project "de.vogella.android.layout.gridlayout" with the Activity called "DemoGridLayout". Change "main.xml" to the following.

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/GridLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="4"
android:useDefaultMargins="true" >

<TextView
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:layout_row="0"
android:text="User Credentials"
android:textSize="32dip" />

<TextView
android:layout_column="0"
android:layout_gravity="right"
android:layout_row="1"
android:text="User Name: " >
</TextView>

<EditText
android:id="@+id/input1"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_row="1"
android:ems="10" />

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

<EditText
android:id="@+id/input1"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_row="2"
android:ems="8" />

<Button
android:id="@+id/button1"
android:layout_column="2"
android:layout_row="3"
android:text="Login" />...
tracking img