Home > Backend Development > XML/RSS Tutorial > Code case sharing for XML layout files

Code case sharing for XML layout files

黄舟
Release: 2017-03-21 16:26:40
Original
2716 people have browsed it

XML layout file

The layout file in xml format is stored in the folder res/layout

The layout methods are mainly LinearLayout (linear layout) and TableLayout (table layout) , RelativeLayout (relative layout)

Of course, there are also AbsoluteLayout, (absolute layout), FrameLayout (frame layout), etc.

They can also be nested to achieve better interface effects

I have sorted out the commonly used attributes based on my personal understanding

It may not be scientific but I think it is very practical.

Control is the whole:

android: ID address

android: width width

android: Height height

android: layout_width width (fill_parent/wrap_content)

android:layout_height (fill_parent/wrap_content)

android:layout_margin(Left/Top/Right/Bottom) Margin (*dip)

Android: Layout_weight.

android:background                                                                                                                                                                . Contents are displayed together (true /false)

Relative layout:

android:layout_above                                                                                                                                               or                     but                                                                Whose bottom edge the edge is aligned with (id)

Android: Layout_toleftof to the right side to align with the left side (ID)

android: layout_torightof to the right side of the right side (ID)

android: layout_aligntop. Alignment ( ID)

Android: Layout_alignbottom. Align with. Who is the right side? The right alignment (id)

android:layout_alignParentTop The top is aligned with the top of the parent control (true/false)

android:layout_alignParentBottom The bottom is aligned with the bottom of the parent control (true/false) True/False)

android: layout_alignparentLeft left to the left side of the parent control (TRUE/FALSE)

android: Layout_alignparentrid to the right of the parent control (TR. UE/FALSE)

android: layout_centerinparent relative to the parent control (True/False)

Android: Layout_CenterHorizontal relative to the level of the parent control level (True/False)

## android: Layout_centervertical Relative to the parent control (True/False)

## ~~~~~~~~~~~~~ ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~

The following is the registration page I just made

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    >
    
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
 
<TextView 
    android:text="欢迎注册" 
    android:gravity="center"
    android:textSize="15pt"
    android:textColor="#ff8c00"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ></TextView>
 
<TextView 
    android:text=" 性别/Gender" 
    android:textSize="8pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ></TextView>
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/genderGroup" android:orientation="horizontal">
<RadioButton android:id="@+id/maleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男"></RadioButton>
<RadioButton android:id="@+id/femaleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女"></RadioButton>

</RadioGroup>
 
<TextView 
    android:text=" 用户名/User" 
    android:textSize="8pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ></TextView>
<EditText 
    android:id="@+id/user" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ></EditText>
 
<TextView 
    android:text=" 密码/Password" 
    android:textSize="8pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ></TextView>
<EditText 
    android:id="@+id/password" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ></EditText>
 
<TextView 
    android:text=" 重复密码/Re-type Password" 
    android:textSize="8pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ></TextView>
<EditText 
    android:id="@+id/rpassword" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ></EditText>
 
<CheckBox 
    android:text="同意注册条款*" 
    android:id="@+id/CheckBox01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    ></CheckBox>
 
</LinearLayout>
 
<TableRow 
    android:layout_alignParentBottom="true"
    android:id="@+id/TableRow01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
<Button 
    android:id="@+id/confirm" 
    android:text="confirm" 
    android:textSize="10pt"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    ></Button>
<Button 
    android:textSize="10pt" 
    android:text="cancel" 
    android:layout_width="wrap_content" 
    android:id="@+id/cancel" 
    android:layout_height="wrap_content"
    android:layout_weight="1"
    ></Button>
</TableRow>
</RelativeLayout>
Copy after login

The above is the detailed content of Code case sharing for XML layout files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template