Android LinearLayout layout instance code

Source: Internet
Author: User

Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<! --
<LinearLayout>
Linear layout configuration. In this label, all components are lined up from top to bottom.
-->
<LinearLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<! -- Android: orientation = "vertical" indicates vertical Alignment
Android: orientation = "horizontal" indicates horizontal alignment
Android: layout_width = "fill_parent" defines the current view on the screen
The consumable width. fill_parent fills the screen.
Android: layout_height = "wrap_content": varies with the text field.
Change the width or height of the view. It means setting the box degree or height automatically.

Layout_weight is used to assign importance values to multiple views in a linear layout.
All views have a layout_weight value. The default value is 0, indicating that the value must be displayed.
The size of the view occupies the size of the blank screen. If a value greater than zero is assigned, the parent
The available space in the image is separated. The split size depends on the layout_weight of each view.
Value and the overall layout_weight value of the value in the current screen layout and
The percentage of the layout_weight value is determined.
For example, we have a text label and two text editing elements in the horizontal direction.
The text label does not specify the layout_weight value, so it occupies the minimum space required.
If the layout_weight value of each of the two text editing elements is set to 1, the two are equally divided.
The remaining width of the layout in the parent view (because we declare that the importance of the two is equal ). If two
In the text editing element, the first value of layout_weight is set to 1, and the second value is set to 2,
Then 2/3 of the remaining space is allocated to the first space, and 1/3 to the second Space (the smaller the value, the more important
Higher Degree ).
-->
<LinearLayout
Android: 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 = "# tianaa"
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>

<LinearLayout
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout_weight = "2">

<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>

It seems that this form is a bit like the layout of div + css, but the flexibility of this method is not as good as that of div + css. It is mainly about how to determine the value of android: layout_weight, in addition, the smaller the value, the higher the importance, and the allocation should be well calculated.

Java code Views. java

Copy codeThe Code is as follows: package com.cn. view;

Import android. app. Activity;
Import android. OS. Bundle;

Public class Views extends Activity {
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.