国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院

首頁 > 系統 > Android > 正文

Android布局(RelativeLayout、TableLayout等)使用方法

2020-01-02 07:01:56
字體:
來源:轉載
供稿:網友

 本文介紹 Android 界面開發中最基本的四種布局LinearLayout、RelativeLayout、FrameLayout、TableLayout 的使用方法及這四種布局中常用的屬性。

  • LinearLayout 線性布局,布局中空間呈線性排列
  • RelativeLayout 相對布局,通過相對定位的方式,控制控件位置
  • FrameLayout 幀布局,最簡單的布局,所有控件放置左上角
  • TableLayout 表格布局,以行列方式控制控件位置

四種布局示例

1.LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical">   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="150dp"    android:orientation="vertical">     <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="垂直1" />    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="垂直2" />  </LinearLayout>   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="100dp"    android:orientation="horizontal">     <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="水平1" />    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="水平2" />  </LinearLayout>   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="150dp"    android:orientation="horizontal">     <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_gravity="top"      android:text="水平上對齊" />    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_gravity="center_vertical"      android:text="水平垂直居中" />    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_gravity="bottom"      android:text="水平下對齊" />  </LinearLayout>   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="100dp"    android:orientation="horizontal">    <EditText      android:layout_width="0dp"      android:layout_height="wrap_content"      android:layout_weight="3"      android:hint="請輸入..."/>    <Button      android:layout_width="0dp"      android:layout_height="wrap_content"      android:layout_weight="2"      android:text="提交" />  </LinearLayout>   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="100dp"    android:orientation="horizontal">    <EditText      android:layout_width="0dp"      android:layout_height="wrap_content"      android:layout_weight="1"      android:hint="請輸入..."/>    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="提交" />  </LinearLayout></LinearLayout>

orientation:horizontal(水平)/vertical(垂直),表示線性排列的方向。
layout_width/layout_height:元素的寬度與高度
layout_gravity:top/bottom/center/left/right/etc,表示當前元素相對父元素的對齊方式,多種對齊方式用“|”隔開,右上對齊:top|right。
layout_weight:占據空間的比例,例如元素A和B,A設置為1,B設置為3, 元素A、B分別占空間的1/4、3/4,此時元素寬度不由layout_width決定,設置為0dp是比較規范的寫法。
layout_weight 若元素A設置為1,元素B不設置,將layout_width設置為具體的值或wrap_content,那么元素B的寬度由layout_width決定,元素A將占滿屏幕剩下的空間。
2.RelativeLayout

<LinearLayout ...>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="300dp">    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_alignParentLeft="true"      android:layout_alignParentBottom="true"      android:text="我在左下"/>    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_centerInParent="true"      android:text="我在中間"/>    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_alignParentRight="true"      android:layout_alignParentTop="true"      android:text="我在右上"/>  </RelativeLayout>   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="300dp">    <Button      android:id="@+id/button_2"      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_centerInParent="true"      android:text="參照按鈕"/>    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_above="@id/button_2"      android:layout_toRightOf="@id/button_2"      android:text="我在右上"/>    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_below="@id/button_2"      android:layout_toLeftOf="@id/button_2"      android:text="我在左下"/>  </RelativeLayout></LinearLayout>

以下屬性值為true/false

layout_centerHorizontal/layout_centerVertical: 水平居中、垂直居中
layout_centerInparent: 相對父元素垂直&水平居中
layout_alignParentBottom: 元素下邊界和父元素下邊界對齊
layout_alignParentLeft: 左邊界對齊
layout_alignParentRight: 右邊界對齊
layout_alignParentTop: 上邊界對齊
以下屬性值為控件id

layout_above/layout_below: 在某元素的上方/下方
layout_toLeftOf/layout_toRightOf: 在某元素的左方/右方
layout_alignTop/layout_alignBottom: 元素上(下)邊界與某元素上(下)邊界對齊
layout_alignLeft/layout_alignRight: 左(右)邊界對齊
3.FrameLayout

所有元素都放置在布局的左上角

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent">   <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="我是一個按鈕"/>  <TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="我是一個輸入框"/></FrameLayout>

4.TableLayout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent">   <TableRow>    <TextView      android:layout_height="wrap_content"      android:text="郵箱"/>    <EditText      android:layout_height="wrap_content"      android:inputType="textEmailAddress"      android:hint="請輸入您的郵箱" />  </TableRow>   <TableRow>    <TextView      android:layout_height="wrap_content"      android:text="密碼"/>    <EditText      android:layout_height="wrap_content"      android:inputType="textPassword"      android:hint="請輸入密碼" />  </TableRow>     <TableRow>    <Button      android:layout_height="wrap_content"      android:layout_span="2"      android:text="注冊" />  </TableRow></TableLayout>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:stretchColumns="1">  ...</TableLayout>

TableRow: 代表表格布局的一行,行內一個元素代表一列。
layout_span: 合并單元格,設置為2,代表該元素占據2列空間。
stretchColumns: TableRow中無法指定空間寬度,那么需要用到該屬性,設置為1,表示拉伸第2列(0為第1列)與屏幕一樣寬,效果如TableLayout的第二張圖。
5.自定義布局

    Android中,布局下可以放置控件,也可以放置子布局。如果子布局內容較為獨立且經常使用,例如標題欄,或者布局比較復雜,這時候可以考慮使用自定義布局的形式導入。方法很簡單。

新建一個布局文件,例如example.xml
在父布局中引入:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:orientation="vertical"   android:layout_width="match_parent"  android:layout_height="match_parent">     <include layout="@layout/example"/> </LinearLayout>

以上就是Android最基本的四種布局的詳細內容介紹,希望對大家的學習有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院
99免费视频| 国产aa视频| www.狠狠操.com| 天堂√中文在线| 免费在线你懂的| 超碰在线观看免费| 日本中文字幕在线视频| 国产一区久久精品| 91在线网站| 日本h片在线观看| 国产在线一二三区| 国产黄色高清在线| 69av二区| 欧美精品小视频| 国产一二三区精品视频| 亚洲日本一区二区三区在线观看| 久热国产在线| 99在线视频观看| 中文字幕免费中文| 四虎影视成人永久免费观看视频| 国产在线高清理伦片a| 精品国产高清自在线一区二区三区| 先锋影音av中文字幕| 国产亚洲精品久久久久久青梅 | 国产毛片在线看| 在线中文av| 福利在线视频导航| av中文字幕在线看| 精品久久亚洲一级α| 国产一二三区精品视频| 白浆爆出在线观看| 在线视频中文字幕| 国产日本在线观看| 1区2区3区在线| 国产精品一区二区三区高清在线| 亚洲一本大道| 中文在线官网天堂| 国产黄网站在线观看| 国产麻豆视频网站| 欧美精品另类| 九色成人在线| 亚洲欧美小说国产图片| 国产三区四区在线观看| 免费视频二区| 操人视频91| 国产在线高潮| 国产精品偷乱一区二区三区| 欧美亚洲系列| 激情综合丁香| 中文字幕网在线| 国产激情视频网址| 精品国产高清a毛片无毒不卡| 国产成人夜间影院在线观看| 91亚洲欧美| 免费a级毛片在线播放| 国产免费永久在线观看| 丁香在线视频| 国产激情视频一区二区三区| 影音av资源站| 国产嫩草在线视频| 精品51国产黑色丝袜高跟鞋| 日本调教视频在线观看| 午夜伦全在线观看| 在线天堂av| 成人欧美日韩| 精品国产一区二区三区久久久狼牙| 伊人222成人综合网| 久草视频国产| 69精品视频| 国产九九九九| 天天艹天天操| 国产偷窥洗澡视频| eeuss影院在线| 国产午夜精品一区理论片| 在线免费观看黄色片| 久久精品最新免费国产成人| 国产精品久久久久一区二区国产| 91麻豆免费在线视频| 国产裸舞福利在线视频合集| 午夜在线观看91| 国产黄在线观看| 福利在线观看| www.狠狠插| 在线黄色国产电影| 国产精品久久人| 99视频资源网| av小说在线| 中文岛国精品亚洲一区| 最新天堂资源在线资源| 欧美96在线| 亚洲欧美久久婷婷爱综合一区天堂| 综合图区亚洲白拍在线| 老司机在线视频二区| 亚洲日本一区二区三区在线观看| 国产精品入口麻豆免费观看| 国产永久免费| 成人欧美亚洲| 国产美女视频一区二区三区| 成年黄网站在线观看免费| 先锋影音av中文字幕| av网站大全在线| 伊人中文字幕在线| 亚洲欧美精品中文第三| jizz性欧美| 粉嫩av一区| 国产三级自拍| 2021av天天| av在线二区| 九九精品视频在线观看九九| 国产九色视频| 在线中文资源天堂| 日本18视频网站| 天堂资源最新在线| 91在线看片| 黄网站在线观看高清免费| 中文字幕第一页在线| 国产污视频在线| 国产粉嫩一区二区三区在线观看| 国产激情视频在线| 国产成人久久精品77777| 精品美女调教视频| 欧美性猛交xxxx免费看蜜桃| 国产无遮挡又黄又爽免费软件| 国产第一页在线视频| www.成人.com| 国产一二区在线| 天天草天天草| 国产精品视频一区麻豆| 在线免费看黄| 国产美女视频一区二区二三区| 国产精品爱久久久久久久小说 | 九九热在线播放| 国产精品久久久精品a级小说| av首页在线| 国产欧美久久久久久久久| 四虎成人欧美精品在永久在线| 午夜视频在线| 久久一本精品| sese一区| 在线视频xx| 精品视频二区三区| 国产精品国产国产aⅴ| 高潮毛片在线观看| 精品麻豆国产| 国产精品视频h| 中文字幕在线视频网| 麻豆精品视频入口| www在线视频| 四虎www视频| 精品极品三级久久久久| 黄网址在线播放免费| av在线日韩国产精品| 中文在线有码| 国产激情99| 国产精品久久久久白浆| 国产蜜臀在线| 超碰国产在线观看| 免费视频中文字幕| 在线国产网址| av在线免费播放| 午夜影院在线| xxxx视频在线| 激情小说 在线视频| 国产在线视频福利| 美女av在线播放| 国产理论电影在线| 日本中文字幕在线视频| 中文字幕久热在线精品| 国产免费电影网站入口| 91sp网站在线观看入口| 国产九九九九| 国产精品伦理一区二区三区| 国产黄在线观看| 国产变态拳头交视频一区二区| 国产人成在线观看| 中文字幕av免费| sese在线视频| 国产香蕉视频在线观看| av福利在线播放| 免费a级人成a大片在线观看| 国产在线资源| 国产福利在线| 天堂中文在线观看| 国产一级黄色| 在线中文av| 成在线人视频免费视频| 国产激情小视频在线| 欧美a免费在线| 国产区在线视频| 日本免费视频www| 国产精品18久久久久网站| 欧洲有码在线视频| 国产精品入口麻豆免费| baoyu777.永久免费视频| 国产三级在线看| 美女被人操视频在线观看| 伊人狠狠av| 精品视频vs精品视频| 国产精品一区二区婷婷| a级片国产精品自在拍在线播放|