XML佈局檔案的程式碼案例分享
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_centerHorizontal 相對父控制水平方向上位(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佈局檔案的程式碼案例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

XML檔可以用PPT開啟嗎? XML,即可擴展標記語言(ExtensibleMarkupLanguage),是一種廣泛應用於資料交換和資料儲存的通用標記語言。與HTML相比,XML更加靈活,能夠定義自己的標籤和資料結構,使得資料的儲存和交換更加方便和統一。而PPT,即PowerPoint,是微軟公司開發的一種用於創建簡報的軟體。它提供了圖文並茂的方

使用Python實現XML資料的合併和去重XML(eXtensibleMarkupLanguage)是一種用於儲存和傳輸資料的標記語言。在處理XML資料時,有時候我們需要將多個XML檔案合併成一個,或移除重複的資料。本文將介紹如何使用Python實現XML資料的合併和去重的方法,並給出對應的程式碼範例。一、XML資料合併當我們有多個XML文件,需要將其合

Python中的XML資料轉換為CSV格式XML(ExtensibleMarkupLanguage)是一種可擴充標記語言,常用於資料的儲存與傳輸。而CSV(CommaSeparatedValues)則是一種以逗號分隔的文字檔案格式,常用於資料的匯入和匯出。在處理資料時,有時需要將XML資料轉換為CSV格式以便於分析和處理。 Python作為一種功能強大

使用Python實現XML資料的篩選和排序引言:XML是一種常用的資料交換格式,它以標籤和屬性的形式儲存資料。在處理XML資料時,我們經常需要對資料進行篩選和排序。 Python提供了許多有用的工具和函式庫來處理XML數據,本文將介紹如何使用Python實現XML資料的篩選和排序。讀取XML檔案在開始之前,我們需要先讀取XML檔案。 Python有許多XML處理函式庫,

Python實作XML與JSON之間的轉換導語:在日常的開發過程中,我們常常需要將資料在不同的格式之間轉換。 XML和JSON是常見的資料交換格式,在Python中,我們可以使用各種函式庫來實作XML和JSON之間的相互轉換。本文將介紹幾種常用的方法,並附帶程式碼範例。一、XML轉JSON在Python中,我們可以使用xml.etree.ElementTree模

使用Python處理XML中的錯誤和異常XML是一種常用的資料格式,用於儲存和表示結構化的資料。當我們使用Python處理XML時,有時可能會遇到一些錯誤和異常。在本篇文章中,我將介紹如何使用Python來處理XML中的錯誤和異常,並提供一些範例程式碼供參考。使用try-except語句捕捉XML解析錯誤當我們使用Python解析XML時,有時候可能會遇到一些

Python解析XML中的特殊字元和轉義序列XML(eXtensibleMarkupLanguage)是一種常用的資料交換格式,用於在不同系統之間傳輸和儲存資料。在處理XML檔案時,經常會遇到包含特殊字元和轉義序列的情況,這可能會導致解析錯誤或誤解資料。因此,在使用Python解析XML檔案時,我們需要了解如何處理這些特殊字元和轉義序列。一、特殊字元和

C#開發中如何處理XML和JSON資料格式,需要具體程式碼範例在現代軟體開發中,XML和JSON是廣泛應用的兩種資料格式。 XML(可擴展標記語言)是一種用於儲存和傳輸資料的標記語言,而JSON(JavaScript物件表示)是一種輕量級的資料交換格式。在C#開發中,我們經常需要處理和操作XML和JSON數據,本文將重點放在如何使用C#處理這兩種數據格式,並附上
