A LinearLayout is a GroupView that will Lay child View elements vertically or horizontally.
1 | <? xml version = "1.0" encoding = "utf-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: orientation = "vertical" android: layout_width = "fill_parent" android: layout_height = "fill_parent"> <LinearLayoutandroid:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"> <TextView android: text = "red "android: gravity =" center_horizontal "android: background =" # aa0000 "android: layout_width =" wrap_content "android: layout_height =" fill_parent "android: layout_weight =" 1 "/> <TextView android: text =" green "android: gravity = "center_horizontal" android: background = "# 00aa00" android: layout_width = "wrap_content" android: layout_height = "fill_parent" android: layout_weight = "1" /> <TextView android: text = "blue" android: gravity = " center_horizontal "android: background =" # 0000aa "android: layout_width =" wrap_content "android: layout_height =" fill_parent "android: layout_weight =" 1 "/> <TextView android: text =" yellow "android: gravity =" center_horizontal "android : background = "# aaaa00" android: layout_width = "wrap_content" android: layout_height = "fill_parent" android: layout_weight = "1" /> </ LinearLayout> <LinearLayoutandroid: orientation = "vertical" android: layout_width = "fill_parent" android : layout_height = "fill_parent" android: layout_weight = "1"> <TextView android: text = "row one" android: textSize = "15pt" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = " 1 "/> <TextView android:text="row two" android:textSize="15pt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <TextView android: text = "row three" android: textSize = "15pt" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = "1" /> <TextView android: text = "row four" android: textSize = "15pt "android: layout_width =" fill_parent "android: layout_height =" wrap_content "android: layout_weight =" 1 "/> </ LinearLayout> </ LinearLayout> |
Carefully inspect the XML. You'll notice how this layout works a lot like an HTML layout. There is one parent LinearLayout that is defined to lay its child elements vertically. The first child is another LinearLayout that uses a horizontal layout and the second uses a Vertical layout. Each LinearLayout contains several TextView elements.
onCreate() method:
1 | public void onCreate (Bundle savedInstanceState) (super.onCreate (savedInstanceState); setContentView (R.layout.main);) |
R.layout.main refers to the main.xml layout file.
You should see the following:

Link Address: http://androidappdocs.appspot.com/guide/tutorials/views/hello-linearlayout.html
Note: LinearLayout is the line of the layout, orientation = "horizontal": horizontally; orientation = "vertical": vertical alignment
To understand: the concept of the layout is similar to the framework, if the custom layout style, then any component inside, all will be arranged in the style. For example: horizontally, then the
Component will be placed side by side a line at a certain level. (Personal understanding)
Tags: android, developed, eclipse, linearlayout, studyPermalink: Code Library - Eclipse developed Android, LinearLayout (study 2)
Subcribe the update with Google Reader.
RSS feed for comments on this post
Leave a reply