Android self-paced linear layout linearlayout

Source: Internet
Author: User

Linear layout (linearlayout), linear layout a bit like the folwlayout in AWT programming, they all arrange the components inside the container.

Their biggest difference is that Android's linear layout does not wrap, and the folwlayout inside the AWT will be displayed on a different line.

LinearLayout support for common XML attributes and the description of related methods

XML properties Related methods Description
Android:gravity setgravity (int) Sets the alignment of components within the layout manager. This property supports Top,bottom,left,right ... You can also create combinations of multiple alignments, such as left|center_vertical that appear on the left side of the screen and are centered vertically.
Android:orientation setorientation (int) Sets how components are arranged in the layout manager. One of two can be set to horizontal (horizontal arrangement), vertical (vertical arrangement, default value)

XML Layout Manager (you can modify android:orientationin Main.xml,android:gravity These two properties, there will be a lot of results displayed)

Layout/main.xml

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:orientation= "vertical"4 Android:layout_width= "Fill_parent"5 Android:layout_height= "Fill_parent"6 android:gravity= "Center_vertical"7     >8     9  <!--android:orientation= "horizontal" level; android:orientation= "vertical" vertical, default -Ten <Button One     Android:id= "@+id/bn1" A Android:layout_width= "Wrap_content"  - Android:layout_height= "Wrap_content"  - Android:text= "@string/bn1" the     /> - <Button -     Android:id= "@+id/bn2" - Android:layout_width= "Wrap_content"  + Android:layout_height= "Wrap_content"  - Android:text= "@string/bn2" +     /> A <Button at     Android:id= "@+id/bn3" - Android:layout_width= "Wrap_content"  - Android:layout_height= "Wrap_content"  - Android:text= "@string/bn3" -     /> - <Button in     Android:id= "@+id/bn4" - Android:layout_width= "Wrap_content"  to Android:layout_height= "Wrap_content"  + Android:text= "@string/bn4" -     /> the <Button *     Android:id= "@+id/bn5" $ Android:layout_width= "Wrap_content" Panax Notoginseng Android:layout_height= "Wrap_content"  - Android:text= "@string/bn5" the     />     + </LinearLayout>

In graphical layout mode:

Values/strings.xml

1 <?XML version= "1.0" encoding= "Utf-8"?>2 3 <Resources>4     <stringname= "BN1">Test button 1</string>5     <stringname= "BN2">Test Button 2</string>6     <stringname= "BN3">Test Button 3</string>7     <stringname= "Bn4">Test Button 4</string>8     <stringname= "Bn5">Test Button 5</string>    9     <stringname= "Bn6">Test Button 6</string>            Ten     <stringname= "App_name">Linear layout</string> One </Resources>

Com.example.linearlayout.MainActivity.java only need to show a layout

1  Packagecom.example.linearlayout;2 3 Importandroid.support.v7.app.ActionBarActivity;4 ImportAndroid.support.v7.app.ActionBar;5 Importandroid.support.v4.app.Fragment;6 ImportAndroid.os.Bundle;7 ImportAndroid.view.LayoutInflater;8 ImportAndroid.view.Menu;9 ImportAndroid.view.MenuItem;Ten ImportAndroid.view.View; One ImportAndroid.view.ViewGroup; A ImportAndroid.os.Build; -  -  Public classMainactivityextendsactionbaractivity { the  - @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.main); -  +          A     } at}

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.