欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中LinearLayout布局的常用屬性總結(jié)

 更新時(shí)間:2016年04月13日 16:07:22   作者:chris930921  
這篇文章主要介紹了Android中LinearLayout布局的常用屬性總結(jié),包括居中、重心、比例等線性布局中的基本設(shè)置,需要的朋友可以參考下

基本屬性要求

<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>

重心設(shè)定

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"

  android:gravity="left">
</LinearLayout>

  • android:gravity
  • 設(shè)定框架的內(nèi)容的放置方向
  • 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 運(yùn)算子組合重心

<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 下的子元件或子框架,才能設(shè)定這項(xiàng)屬性。

等比例分配

<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% 分配。      

相關(guān)文章

  • android 如何判斷當(dāng)前是否為飛行模式

    android 如何判斷當(dāng)前是否為飛行模式

    android 開發(fā)過程中如何判斷當(dāng)前是否是飛行模式和偵聽airplane mode change,本文將以此問題詳細(xì)介紹,需要了解的朋友可以參考下
    2012-11-11
  • Android UI實(shí)現(xiàn)單行文本水平觸摸滑動(dòng)效果

    Android UI實(shí)現(xiàn)單行文本水平觸摸滑動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了Android UI實(shí)現(xiàn)單行文本水平觸摸滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Flutter替換字符串中的html標(biāo)簽

    Flutter替換字符串中的html標(biāo)簽

    這篇文章主要為大家介紹了Flutter替換字符串中的html標(biāo)簽實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2023-05-05
  • Android中drawable使用Shape資源

    Android中drawable使用Shape資源

    這篇文章主要為大家詳細(xì)介紹了Android中drawable使用Shape資源的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Android使用Notification實(shí)現(xiàn)通知功能

    Android使用Notification實(shí)現(xiàn)通知功能

    這篇文章主要為大家詳細(xì)介紹了Android使用Notification實(shí)現(xiàn)通知功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Flutter持久化存儲(chǔ)之?dāng)?shù)據(jù)庫存儲(chǔ)(sqflite)詳解

    Flutter持久化存儲(chǔ)之?dāng)?shù)據(jù)庫存儲(chǔ)(sqflite)詳解

    這篇文章主要給大家介紹了關(guān)于Flutter持久化存儲(chǔ)之?dāng)?shù)據(jù)庫存儲(chǔ)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • android使用AIDL跨進(jìn)程通信(IPC)

    android使用AIDL跨進(jìn)程通信(IPC)

    本篇文章主要介紹了 android跨進(jìn)程通信(IPC):使用AIDL,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • 基于Android實(shí)現(xiàn)數(shù)獨(dú)游戲

    基于Android實(shí)現(xiàn)數(shù)獨(dú)游戲

    這篇文章主要為大家詳細(xì)介紹了基于Android實(shí)現(xiàn)數(shù)獨(dú)游戲,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android 仿網(wǎng)易新聞客戶端分類排序功能

    Android 仿網(wǎng)易新聞客戶端分類排序功能

    這篇文章主要介紹了Android 仿網(wǎng)易新聞客戶端分類排序功能,實(shí)現(xiàn)此功能涉及到拖拽item及隱藏拖拽的Item的方法,本文給大家介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2016-12-12
  • Android時(shí)間日期拾取器學(xué)習(xí)使用(DatePicker、TimePicker)

    Android時(shí)間日期拾取器學(xué)習(xí)使用(DatePicker、TimePicker)

    這篇文章主要為大家詳細(xì)介紹了Android提供的DatePicker日期拾取器和TimePicker時(shí)間拾取器的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02

最新評(píng)論