A brief analysis of the linear layout linearlayout examples of Android programming _android

Source: Internet
Author: User

This example describes the linear layout linearlayout usage of Android programming. Share to everyone for your reference, specific as follows:

Linear layout (LinearLayout)

You can have its child elements line up vertically or horizontally (the default is in the vertical direction without setting the orientation).

The following examples are main.xml modified on the basis of others:

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical " > <linearlayout android:orientation= "Horizontal" android:layout_width= "Fill_parent" Android:layout_hei ght= "Wrap_content" android:baselinealigned= "false" android:layout_weight= "1" > <linearlayout Andro id:orientation= "Horizontal" android:layout_width= "Wrap_content" android:layout_height= "Fill_parent" Andr oid:layout_weight= "1" > <textview android:text= "@string/color_green" android:textcolor= "#ff0000 "Android:background=" #00aa00 "android:layout_width=" wrap_content "android:layout_height=" Fill_par Ent "android:layout_weight=" 1 "/> <textview android:text=" @string/color_blue "android:b Ackground= "#0000aa" Android:laYout_width= "Wrap_content" android:layout_height= "Fill_parent" android:layout_weight= "1"/> </Line
       arlayout> <linearlayout android:orientation= "vertical" android:layout_width= "wrap_content" android:layout_height= "Fill_parent" android:layout_weight= "1" > <textview android:text= "@strin G/color_black "android:background=" "#000000" android:layout_width= "Fill_parent" Android:layout_h eight= "Wrap_content" android:layout_weight= "1"/> <textview android:text= "@string/color_yell ow "android:background=" #aaaa00 "android:layout_width=" fill_parent "android:layout_height=" wrap
         _content "android:layout_weight=" 1 "/> <textview android:text=" @string/color_unknown "
         Android:background= "#00aaaa" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:layout_weight= "1"/> </LinearLayout> </LinearLayout> <linearlayout android:orientation= "vertical" Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "2" > <T
      Extview android:text= "@string/color_red" android:gravity= "fill_vertical" android:background= "#aa0000"
    Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "2"/> <textview android:text= "@string/color_white" android:textcolor= "#ff0000" android:background= "#ffffff 
  "Android:layout_width=" fill_parent "android:layout_height=" Wrap_content "android:layout_weight=" 2 "/>

 </LinearLayout> </LinearLayout>

String.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
  <string name= "Hello" >hello world, testabsolutelayoutactivity!</string>
  <string name= "App_name" >TestAbsoluteLayout</string>
  <string name= "color_red" >red</string>
  <string name= "Color_green" >green</string>
  <string name= "Color_blue" >blue</string>
  <string name= "Color_white" >white</string >
  <string name= "Color_black" >black</string>
  <string name= "Color_yellow" >yellow</ string>
  <string name= "Color_unknown" >unknown</string>
</resources>

The effect chart is as follows:

Common Properties:

Android:orientation: You can set the direction of the layout
android:gravity: Used to control the alignment of components
layout_weight: controls the relative size of each component in the layout

More about Android programming layout to view the site topics: "Android Layout layout Skills Summary"

I hope this article will help you with the Android program.

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.