Android Common layout controls LinearLayout and Tablelayout

Source: Internet
Author: User
Tags relative xml attribute

One, LinearLayout layout control

XML attribute

Android:baselinealigned: Allows the user to adjust the baseline of its content.

Android:baselinealignedchildindex: When a linear layout is part of a baseline alignment with another layout, it can specify the baseline alignment of its content.

Android:gravity: Specifies the basic content of the content in the control.

Android:orientation: Sets the direction of its content, with two values to choose from: Horizontal and vertical. Represents a horizontal and vertical arrangement, respectively.

LinearLayout is a linear layout control that contains child controls that are arranged in a horizontal or vertical manner, arranging all widgets or other containers in relative positions, and some controls will be missing or disappear when they exceed the bounds, and cannot be fully displayed. So when vertically arranged, each row would have only one widget or container, regardless of how wide they were, and the horizontal arrangement would have only one row height (the height of the highest child control plus the height of the border). LinearLayout maintains the spacing between the widgets it contains or the container, and aligns (relative to the right, center, or left alignment of a control).

LinearLayout also supports specifying padding weights for the widgets it contains or container. Allow it to contain widgets or container to fill the remaining space on the screen. The remaining space is allocated to the screen according to the weights specified in these widgets or containers. The default weight value is 0, which indicates that the actual size of the widgets or containers is displayed, and if the value is higher than 0, the remaining free space will be container split, depending on each widget or container layout_ Weight and the proportion of the weight in all widgets or containers. For example, if you have three text boxes, the first two text boxes have a value of 2 and 1, and 2/3 of the remaining space after the third text box is 2, and 1/3 for the size of 1. The third text box is not magnified and is displayed in actual size. That is, the larger the weight, the greater the importance, the greater the amount of space to display.

LinearLayout Example:

Layout file:

01.<?xml version= "1.0" encoding= "Utf-8"?> 02.
03.<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android" 04.
android:orientation= "Horizontal" 06.
Android:layout_width= "Fill_parent" 08.
android:layout_height= "Fill_parent" 10.
> 12.
<!--14.
Android:id ———————————— Specify ID 16 for the control.
Android:text —————————— The text displayed in the specified control 18.
Android:gravity ——————— Specify the basic position of the content in the control, such as center, right, and so on 20.
Android:textsize —————— Specifies the size of the font in the control 22.
Android:background ———— Specify the background color used by the control, RGB naming method 24.
Android:width ————————— Specify the width of the control 26.
Android:height ———————— Specifies the height of the control 28.
Android:padding ——————— Specify the four-direction inner margin of the control 30.
Android:paddingleft ———— Specify the left inner margin of the control 32.
Android:paddingright ——— Specify the right inner margin of the control 34.
Android:paddingtop ———— Specify the upper and inner margin of the control 36.
android:paddingbottom-Specifies the bottom margin of the control 38.
Android:sigleline ————— If set to True, the contents of the control are displayed on one line 40.
android:layout_weight-set the padding weight value of 42 in the LinearLayout control.    43.--> 44.
45.<textview 46.
Android:id= "@+id/first" 48.
Android:layout_width= "200dip" 50.
Wuyi android:layout_height= "200dip" 52.
Android:text= "The first TextView" 54.
Android:textsize= "20pt" 56.
Android:gravity= "Center_vertical" 58.
Android:background= "#aa0000" 60.
android:paddingleft= "10dip" 62.
android:paddingright= "30dip" 64.
android:paddingtop= "10dip" 66.
Android:paddingbottom= "30dip" 68.
android:layout_weight= "2" 70.
/> 72.
73.<textview 74.
Android:id= "@+id/second" 76.
Android:layout_width= "200dip" 78.
Android:layout_height= "200dip" 80.
Bayi. android:text= "The second TextView" 82.
Android:textsize= "20PT" 84.
Android:gravity= "Center_vertical" 86.
Android:background= "#0000aa" 88.
Android:paddingleft= "10dip" 90.
android:paddingright= "30dip" 92.
android:paddingtop= "10dip" 94.
Android:paddingbottom= "30dip" 96. Android:layout_weig.ht= "1" 98.
/> 100. 101.

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.