Android base TOP3: Features of linear layout, common attributes, and weight values, androidtop3

Source: Internet
Author: User

Android base TOP3: Features of linear layout, common attributes, and weight values, androidtop3

Linear layout is a horizontal or vertical layout of views;

Common attributes:

Androuid: orientation: indicates the layout direction

  • The vertical value indicates the vertical layout.
  • The value horizontal indicates horizontal layout.

Android: gravity indicates view alignment

  • Content includes TOP, bottom, left, right, center_vertical, center_horizontal, center
  • You can use "|" to separate multiple values.

The following attributes can be used for a view in the layout:

Android: layout_gravity indicates the alignment of a single view

Android: layout_weight indicates the proportion of the size of a single view

  • When Layout_weight is 0, the View Size is determined.
  • When layout_weight is greater than 0, the view is stretched according to the specific gravity in the linear layout direction.

Code Demonstration:

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="horizontal" > 6     <Button  7         android:layout_width="200dp" 8         android:layout_height="100dp" 9         android:text="adaflkjn"10         android:gravity="bottom|center_horizontal"/>11 12 </LinearLayout>

Android: gravity: determines the position of elements in the control.
<Button         android:layout_width="200dp"        android:layout_height="100dp"        android:text="adaflkjn"        android:layout_gravity="center"/>

 

Android: layout_gravity indicates the position of the current element in the parent element.

Weight applications

<EditText        android:layout_width="0dp"       android:layout_height="wrap_content"       android:layout_weight="1"       android:hint="sdaf"/>   <Button        android:layout_width="1dp"       android:layout_height="wrap_content"       android:layout_weight="0"       android:text="klndgjl"       />

<TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = "0" android: text = "weight 0" android: background = "# FFF0F5"/> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "weight is 1" android: layout_weight = "1" android: background = "#800080"/> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "weight is 4" android: layout_weight = "4" android: background = "#4B0082"/>

 

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.