日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Android:layout_weight详解

發(fā)布時間:2023/12/16 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android:layout_weight详解 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(zhuǎn)載請標(biāo)明出處:http://blog.csdn.net/xx326664162/article/details/51721142 文章出自:薛瑄的博客

你也可以查看我的其他同類文章,也會讓你有一定的收貨!

簡介

android:layout_weight的真實(shí)含義是:一旦View設(shè)置了該屬性(假設(shè)有效的情況下),那么該 View的寬度等于原有寬度(android:layout_width)加上剩余空間的占比!

計(jì)算公式:

控件A最終寬度 = 控件A初始寬度+(屏幕寬度 - 控件寬度和)* 控件A的weight的值 /所有weight之和

下面分析中所提到的剩余寬度 = 屏幕寬度 - 控件寬度和

舉例:

上圖的六條,分表對應(yīng)下面的六段代碼,具體解析在每段代碼后。

一、

<LinearLayoutandroid:layout_width="match_parent"android:orientation="horizontal"android:layout_marginTop="20dp"android:layout_height="50dp"><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:background="@color/blue"android:layout_height="match_parent" /><TextViewandroid:layout_weight="2"android:layout_width="0dp"android:background="@color/red"android:layout_height="match_parent" /><TextViewandroid:layout_weight="3"android:background="@color/yellow"android:layout_width="0dp"android:layout_height="match_parent" /></LinearLayout>

二、

<LinearLayoutandroid:layout_width="match_parent"android:orientation="horizontal"android:layout_marginTop="20dp"android:layout_height="50dp"><TextViewandroid:layout_weight="1"android:layout_width="match_parent"android:background="@color/blue"android:layout_height="match_parent" /><TextViewandroid:layout_weight="2"android:layout_width="match_parent"android:background="@color/red"android:layout_height="match_parent" /><TextViewandroid:layout_weight="3"android:background="@color/yellow"android:layout_width="match_parent"android:layout_height="match_parent" /></LinearLayout>

設(shè)屏幕寬度為L,在三個view的寬度都為match_parent的情況下,原有寬度為L,三個的View的寬度都為L,剩余寬度為L-(L+L+L) = -2L

三個TextView的寬度依次為:
L+(-2L)*1/6 = (2/3)L
L+(-2L)*2/6 = (1/3)L
L+(-2L)*3/6 = (0)L

這就是為什么layout_weight設(shè)置越大顯示的占比反而越小,甚至是不顯示的原因

事實(shí)上默認(rèn)的View的weight這個值為0,一旦設(shè)置了這個值,那么所在view在繪制的時候執(zhí)行onMeasure兩次的原因就在這。

三、

<LinearLayoutandroid:layout_width="match_parent"android:orientation="horizontal"android:layout_marginTop="20dp"android:layout_height="50dp"><TextViewandroid:layout_weight="1"android:layout_width="100dp"android:background="@color/blue"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:background="@color/red"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:background="@color/yellow"android:layout_width="0dp"android:layout_height="match_parent" /></LinearLayout>

設(shè)屏幕寬度為L,剩余寬度為L-(100dp)

三個TextView的寬度依次為:
100+(L-(100dp))*1/3
0+(L-(100dp))*1/3
0+(L-(100dp))*1/3

相當(dāng)于是把L-100dp平均分為6分,然后按比重劃分給每個view
最后把100dp加到指定的view上

四、

<LinearLayoutandroid:layout_width="match_parent"android:orientation="horizontal"android:layout_marginTop="20dp"android:layout_height="50dp"><TextViewandroid:background="@color/black"android:layout_width="100dp"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:background="@color/blue"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:background="@color/red"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:background="@color/yellow"android:layout_width="0dp"android:layout_height="match_parent" /></LinearLayout>

為了驗(yàn)證代碼三是正確的,所以代碼四中,加了一段寬度為100dp的黑色塊,結(jié)果三和四的顯示比例一樣

五、

<LinearLayoutandroid:layout_width="match_parent"android:orientation="horizontal"android:layout_marginTop="20dp"android:layout_height="50dp"><TextViewandroid:layout_weight="1"android:layout_width="wrap_content"android:background="@color/blue"android:text="123456789123456789"android:textColor="@color/white"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:background="@color/red"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:background="@color/yellow"android:layout_width="0dp"android:layout_height="match_parent" /></LinearLayout>

第一個view的 android:layout_width=“wrap_content”,所以初始寬度為text的長度

設(shè)屏幕寬度為L,剩余寬度為L-(text的長度)

三個TextView的寬度依次為:
text的長度+(L-(text的長度))*1/3
0+(L-(text的長度))*1/3
0+(L-(text的長度))*1/3

六、

<LinearLayoutandroid:layout_width="match_parent"android:orientation="horizontal"android:layout_marginTop="20dp"android:layout_height="50dp"><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:background="@color/blue"android:text="123456789123456789"android:textColor="@color/white"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:background="@color/red"android:layout_height="match_parent" /><TextViewandroid:layout_weight="1"android:background="@color/yellow"android:layout_width="0dp"android:layout_height="match_parent" /></LinearLayout>

設(shè)屏幕寬度為L,三個view指定的android:layout_width都是0,所以剩余寬度為L

三個TextView的寬度依次為:
0+(L)*1/3
0+(L)*1/3
0+(L)*1/3

參考:
http://www.cnblogs.com/zhmore/archive/2011/11/04/2236514.html
http://m.blog.csdn.net/article/details?id=24667299
http://renyuan-1991.iteye.com/blog/2272200

總結(jié)

以上是生活随笔為你收集整理的Android:layout_weight详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 未满十八18禁止免费无码网站 | 国产乱淫av公| 久久理论电影 | av美女在线| 九九九久久久精品 | 91九色国产 | 91禁国产网站 | 中文字幕丝袜 | 美梦视频大全在线观看高清 | 国产国语老龄妇女a片 | 在线se | 日韩成人免费在线观看 | 特黄三级 | 国产喷白浆一区二区三区 | 国产一级一区 | 亚洲一级一区 | av中文字幕免费在线观看 | 国产伦精品一区二区三区高清版 | 亚洲一级电影 | 亚洲高清视频免费观看 | 欧美色图19p | 欧美一级大片在线观看 | 久久精品国产亚洲av成人 | 亚洲一级二级 | 欧美日韩不卡一区 | 欧美午夜精品久久久久久蜜 | 午夜视频黄色 | 天堂视频免费 | 精品一区二区三区免费观看 | 东北熟女一区二区三区 | 三级少妇 | 男人操女人的免费视频 | 免费在线性爱视频 | 免费成人高清视频 | 午夜伦理在线观看 | 午夜福利一区二区三区 | 91影院在线播放 | 亚洲国产视频一区 | 真人毛片97级无遮挡精品 | 中文字幕一区电影 | av午夜天堂| 99久久网站 | 国产经典三级在线 | 免费国产黄 | 国产乱子伦精品视频 | 综合网久久 | 波多野结衣av在线免费观看 | av毛片网| 免费日韩视频 | 一眉道姑 | 日本成人动漫在线观看 | 成人福利在线免费观看 | 欧美r级在线 | 边打电话边做 | av观看一区 | 天天操天天操天天操 | 人妻精品无码一区二区三区 | 色香欲综合网 | 日韩av一区二区在线观看 | 麻豆av免费在线观看 | 一级黄色大全 | 亚洲射吧| 免费一级片视频 | 永久看看免费大片 | 日韩成人三级 | 五月天激情小说 | 贵族女沦为官妓h呻吟 | 8x8x永久免费视频 | 天海翼中文字幕 | 国产一区二区黄 | 黄色av网站免费观看 | 欧美xxxx精品 | 四虎激情 | 国产在线视频卡一卡二 | 国产欧美一区在线观看 | 99久久久无码国产精品 | 黄色图片小说 | 国产伦精品一区二区三区免.费 | 少妇伦子伦精品无吗 | 免费在线观看视频a | 国产精品一区二区三区久久 | 看成人片 | 中国男女全黄大片 | 亚洲视频www | 国产伊人久久 | 免费av网站在线 | 香港黄色网址 | 国产美女免费网站 | 亚欧美精品| 男女做爰猛烈吃奶啪啪喷水网站 | 久久影院中文字幕 | 成人免费观看网址 | 欧美一区二区影院 | 日韩成人av网站 | 丰满大乳奶做爰ⅹxx视频 | 一级美女黄色片 | www国产精品内射老熟女 | 久草手机在线 | 日本泡妞视频 |