XML佈局檔案的程式碼案例分享

黄舟
發布: 2017-03-21 16:26:40
原創
2622 人瀏覽過

XML佈局檔案

在資料夾res/layout中存放著xml格式的佈局檔案

佈局方式主要是LinearLayout(線性佈局) 、TableLayout(表格佈局) 、RelativeLayout(相對佈局) 

當然還有AbsoluteLayout、(絕對佈局)、FrameLayout(幀佈局)等等

他們之間也可以透過嵌套達到更好的介面效果

我依照個人的理解將常用的屬性整理了一下

可能不科學 但我認為很實用。

控制整體:

    android:id                                                                      寬度

##           高度

    android:layout_width                           (fill_parent/wrap_content)

    android:layout_height                             外邊距(*dip)

# android:layout_weight                             比重

#控制

             文字內容

    android:textSize                                                    基本內容位置

    android:background                               背景顏色中(RBG)

##  singleLine                                  內容中所顯示(true /false)

相對佈局:

##  android:layout_above                              下邊與誰的上邊上與誰的上邊#                        上邊與誰的下方對齊(id)

    android:layout_toLeftOf                             右邊與誰的左邊對齊(         左邊與誰的右邊對齊(id)

   android:layout_alignTop                                      id)

    android:layout_alignBottom                       下與誰的下位對準(id) ##        左邊與誰的左邊對齊(id) 

    android:layout_alignRight                     的右方對齊(id)

 

    android:layout_alignParentTop                  上邊與父親控制下邊與父控制項的下邊對齊( true/false)

    android:layout_alignParentLeft                  左邊與父控制的左邊對齊(true/false)# 右邊對齊(true/false)

    android:layout_centerInParent                   相對父控制居中(true/false)        

    android:layout_centerHorizo​​​​ntal                 相對父控制水平方向上位(true/false)

    and  alse)

~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~

下面給出我剛做好的註冊頁面

<?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>
登入後複製

XML佈局檔案的程式碼案例分享

#

以上是XML佈局檔案的程式碼案例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!