国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android中LinearLayout布局的常用屬性總結

2019-12-12 06:36:23
字體:
來源:轉載
供稿:網友

基本屬性要求

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"> </LinearLayout>
  • android:orientation
  • 決定是水平排列或是垂直排列
  • vertical 垂直排列
  • horizontal 水平排列

垂直排列 Button

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical" >  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1" />  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 2" /></LinearLayout>

水平排列 Button

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical" >  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1" />  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 2" /></LinearLayout>

重心設定

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:gravity="left"></LinearLayout>
  • android:gravity
  • 設定框架的內容的放置方向
  • center 水平垂直皆置中
  • center_vertical 垂直置中
  • center_horizontal 水平置中
  • top 置頂
  • left 置左
  • bottom 置底
  • right 置右

水平、垂直置中

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:gravity="center_vertical">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1" /></LinearLayout><LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:gravity="center_horizontal">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1" /></LinearLayout><LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:gravity="center">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1" /></LinearLayout>

透過 OR 運算子組合重心

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:gravity="top|right">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1" /></LinearLayout><LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:gravity="bottom|left">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1" /></LinearLayout><LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:gravity="center_vertical|center_horizontal">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1" /></LinearLayout>

比例分配

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="horizontal">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1"    android:layout_weight="1"/></LinearLayout>
  • android:layout_weight
  • 子元件或子框架的比重。
  • LinearLayout 下的子元件或子框架,才能設定這項屬性。

等比例分配

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="horizontal">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1"    android:layout_weight="1"/>  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 2"    android:layout_weight="1"/>  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 3"    android:layout_weight="1"/></LinearLayout>

比重都是 1,所以大小相同。


非等比例分配

<LinearLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="horizontal">  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 1"    android:layout_weight=".10"/>  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 2"    android:layout_weight=".20"/>  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Button 3"    android:layout_weight=".70"/></LinearLayout>

.10 代表 0.10
.20 代表 0.20
.70 代表 0.70
合起來剛好是 1 ,作 100% 分配。      

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 尖扎县| 上思县| 四子王旗| 淳化县| 阳高县| 嘉定区| 普陀区| 金川县| 莱芜市| 咸阳市| 三亚市| 永川市| 柳江县| 台东市| 旬阳县| 鹤山市| 六安市| 定边县| 无极县| 沙坪坝区| 横山县| 阳信县| 乐都县| 嘉禾县| 乌鲁木齐县| 陆丰市| 嘉黎县| 务川| 祁连县| 白水县| 田林县| 肇东市| 清徐县| 靖西县| 平阳县| 雷山县| 巴彦淖尔市| 碌曲县| 兴海县| 渝中区| 桂林市|