Android Base LinearLayout layout

Source: Internet
Author: User

LinearLayout layout:

<?xml version= "1.0" encoding= "Utf-8"?>

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"

Xmlns:tools= "Http://schemas.android.com/tools"

Android:layout_width= "Match_parent"

android:layout_height= "Match_parent"

android:orientation= "Horizontal"

>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button1"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button2"

/>

<button

android:layout_height= "Wrap_content"

Android:layout_width= "Wrap_content"

android:text= "Button3"

/>

</LinearLayout>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/30/55/wKiom1Ok-byThkYcAACBGrLC1Nc445.jpg "title=" 2014-06-21_100921.png "alt=" Wkiom1ok-bythkycaacbgrlc1nc445.jpg "/>

LinearLayout Nesting of layouts:

<?xml version= "1.0" encoding= "Utf-8"?>

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"

Xmlns:tools= "Http://schemas.android.com/tools"

Android:layout_width= "Match_parent"

android:layout_height= "Match_parent"

android:orientation= "Horizontal"

>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button1"

/>

<linearlayout android:orientation= "Vertical"

Android:layout_width= "Fill_parent"

android:layout_height= "Wrap_content"

>

<button

android:text= "Button2"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

/>

<button

android:layout_height= "Wrap_content"

Android:layout_width= "Wrap_content"

android:text= "Button3"

/>

</LinearLayout>

</LinearLayout>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/30/55/wKioL1Ok-czxitJZAACC5WlSnVI216.jpg "title=" 2014-06-21_101410.png "alt=" Wkiol1ok-czxitjzaacc5wlsnvi216.jpg "/>

Layout_weight Properties:

All components have this property, default to 0 if not set, and its properties represent how large a view is currently.

If its value is greater than 0, it means that the free space in the parent view is split

The sample code is as follows:

<?xml version= "1.0" encoding= "Utf-8"?>

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"

Xmlns:tools= "Http://schemas.android.com/tools"

Android:layout_width= "Match_parent"

android:layout_height= "Match_parent"

android:orientation= "Vertical"

>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button1"

android:layout_weight= "1"

/>

<button

android:text= "Button4"

android:layout_height= "Wrap_content"

Android:layout_width= "Wrap_content"

android:layout_weight= "1"

/>

</LinearLayout>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/30/55/wKiom1Ok-gzxiEBZAAB3tzxyTW0977.jpg "title=" 2014-06-21_104118.png "alt=" Wkiom1ok-gzxiebzaab3tzxytw0977.jpg "/>

Properties commonly used in linear layouts:

1:gravity: Each component defaults to the upper-left corner of its value alignment. This property allows you to adjust the alignment of components such as how to left. Right or center alignment, etc.,

Padding of the 2:padding margin, also known as the inner margin. Refers to the margin between the current layout and the contained components

Android:paddingtop

Android:paddingbottom

Android:paddingleft

Android:paddingright

Android:padding represents a uniform adjustment around the four-direction margin

3:layout_margin: Margin. Refers to the margin between the other components.

Android:layout_margintop

Android:layout_marginbottom

Android:layout_marginleft

Android:layout_marginright

Android:layout_margin to set four direction margin uniform adjustment

A more comprehensive example:

<?xml version= "1.0" encoding= "Utf-8"?>

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"

Xmlns:tools= "Http://schemas.android.com/tools"

Android:layout_width= "Match_parent"

android:layout_height= "Match_parent"

android:orientation= "Vertical"

>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button1"

android:layout_gravity= "Bottom"

android:paddingtop= "10DP"

/>

<button

android:text= "Button4"

android:layout_height= "Wrap_content"

Android:layout_width= "Wrap_content"

android:layout_gravity= "Bottom"

android:layout_marginleft= "50DP"

android:layout_margintop= "30DP"

/>

<button

android:text= "Button2"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:layout_gravity= "Bottom"

android:paddingleft= "60DP"

Android:paddingbottom= "60DP"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button3"

Android:layout_gravity= "Right"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button6"

Android:layout_gravity= "Right"

android:layout_marginright= "40DP"

android:layout_margintop= "40DP"

/>

</LinearLayout>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/30/55/wKioL1Ok-fGAry2-AAEdrcH5frE695.jpg "title=" 2014-06-21_111310.png "alt=" Wkiol1ok-fgary2-aaedrch5fre695.jpg "/>

This article is from the "Hagar" blog, make sure to keep this source http://7832308.blog.51cto.com/7822308/1429181

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.