Android user interface-Layout

Source: Internet
Author: User

Application of various la s in Android and implementation of menu Effects

    • Applications with various layout modes: framelayout, linearlayout, tablelayout, absolutelayout, and relativelayout
    • Configure the context menu for the specified element as the applicationProgramConfiguration option menu and multi-level menu implementation

Demonstration of various layout Modes
Res/layout/Main. xml

Code

<? XML version = "1.0" encoding = "UTF-8" ?>
<! --  
Layout_width-width. Fill_parent: The width follows the parent element; wrap_content: The width follows the content; specify a PX value directly to set the width.
Layout_height-height. Fill_parent: The height follows the parent element; wrap_content: The height follows the content; specify a PX value directly to set the height.
-->

<! --
Linearlayout-linear layout.
Orientation-Arrangement of elements in a container. Vertical: vertical arrangement of child elements; Horizontal: horizontal arrangement of child elements
Gravity-content arrangement. Top, bottom, left, right, and center are commonly used. For details, see the documentation.
-->
< Linearlayout Xmlns: Android = "Http://schemas.android.com/apk/res/android"
Android: Orientation = "Vertical" Android: gravity = "Right"
Android: layout_width = "Fill_parent" Android: layout_height = "Fill_parent" >

<! --
Framelayout-stacked layout. Starts from the upper left corner and overwrites the elements in framelayout.
-->
< Framelayout Android: layout_height = "Wrap_content"
Android: layout_width = "Fill_parent" >
< Textview Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content" Android: Text = "Framelayout" >
</ Textview >
< Textview Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content" Android: Text = "Frame layout" >
</ Textview >
</ Framelayout >

<TextviewAndroid: layout_width= "Wrap_content"
Android: layout_height= "Wrap_content"Android: Text= "@ String/hello" />

<! --
Tablelayout-table layout.
Tablerow-rows in the Table. Each element in the row is counted as one column.
Collapsecolumns-set the column indexes of columns to be hidden in tablelayout. Multiple columns are separated by commas (,).
Stretchcolumns-set the index of the columns in tablerow in tablelayout that need to be stretched (the column is stretched to all available spaces). Multiple columns are separated by commas (,).
Shrinkcolumns-set the column indexes of the tablerow in tablelayout to be shrunk (to prevent other columns from being squeezed out of the screen, this column will automatically contract). Multiple columns are separated by commas (,).
-->
< Tablelayout Android: ID = "@ + ID/tablelayout01"
Android: layout_width = "Fill_parent" Android: layout_height = "Wrap_content"
Android: collapsecolumns = "1" >
< Tablerow Android: ID = "@ + ID/tablerow01" Android: layout_width = "Fill_parent"
Android: layout_height = "Wrap_content" >
< Textview Android: layout_width = "Wrap_content"
Android: layout_weight = "1" Android: layout_height = "Wrap_content"
Android: Text = "Row 1 column 1"   />
< Textview Android: layout_width = "Wrap_content"
Android: layout_weight = "1" Android: layout_height = "Wrap_content"
Android: Text = "Row 1 column 2"   />
< Textview Android: layout_width = "Wrap_content"
Android: layout_weight = "1" Android: layout_height = "Wrap_content"
Android: Text = "Row 1 column 3"   />
</ Tablerow >
< Tablerow Android: ID = "@ + ID/tablerow01" Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content" >
< Textview Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content" Android: Text = "Row 2 column 1"   />
</ Tablerow >
</ Tablelayout >

<! --
Absolutelayout-absolutely locates the layout.
Layout_x-X coordinates. Vertex in the upper left corner
Layout_y-y coordinate. Vertex in the upper left corner
-->
< Absolutelayout Android: layout_height = "Wrap_content"
Android: layout_width = "Fill_parent" >
< Textview Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content" Android: Text = "Absolutelayout"
Android: layout_x = "100px"  
Android: layout_y = "100px"   />
</ Absolutelayout >

<! --
Relativelayout-relative positioning layout.
Layout_centerinparent-place the current element in the center of the horizontal and vertical directions of the container (similar attributes include layout_centerhorizontal and layout_alignparentleft)
Layout_marginleft-set the distance between the current element and the left edge of its container
Layout_below-place the current element under the specified Element
Layout_alignright-the current element is right aligned with the specified Element
-->
< Relativelayout Android: ID = "@ + ID/relativelayout01"
Android: layout_width = "Fill_parent" Android: layout_height = "Fill_parent" >
< Textview Android: layout_width = "Wrap_content" Android: ID = "@ + ID/ABC"
Android: layout_height = "Wrap_content" Android: Text = "Centerinparent = true"
Android: layout_centerinparent = "True"   />
< Textview Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content" Android: Text = "Marginleft = 20px"
Android: layout_marginleft = "20px"   />
< Textview Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content" Android: Text = "XXX"
Android: layout_below = "@ ID/ABC" Android: layout_alignright = "@ ID/ABC"   />
</ Relativelayout >

</Linearlayout>

Res/values/strings. xml

<? XML version = "1.0" encoding = "UTF-8" ?>
< Resources >
< String Name = "Hello" > Hello Layout </ String >
< String Name = "App_name" > Webabcd_layout </ String >
</ Resources >

Main. Java

Code

Package Com. webabcd. layout;

ImportAndroid. App. activity;
ImportAndroid. OS. Bundle;

Public   Class Main Extends Activity {
/** Called when the activity is first created. */
@ Override
Public   Void Oncreate (bundle savedinstancestate ){
Super . Oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
}
}

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.