色yeye在线视频观看_亚洲人亚洲精品成人网站_一级毛片免费播放_91精品一区二区中文字幕_一区二区三区日本视频_成人性生交大免费看

當前位置:首頁 > 嵌入式培訓 > 嵌入式學習 > 講師博文 > LinearLayout的權重屬性

LinearLayout的權重屬性 時間:2018-09-25      來源:未知

LinearLayout子控件重要的屬性 android:layout_weight, 值為整數, 默認為0

1 當父控件LinearLayout中android:orientation="vertical"時

子控件高度 = 子控件原本高度 + (父控件LinearLayout高度 - 所有子控件高度之和) * 子控件高度權重比

2 當父控件LinearLayout中android:orientation="horizontal",

子控件寬度 = 子控件原本寬度 + (父控件LinearLayout寬度 - 所有子控件寬度之和) * 子控件寬度權重比

(match_parent或fill_parent都指父控件高度或寬度)

例1:

<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

>

<TextView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:textColor="#f00"

android:background="#0f0"

android:text="上面"

android:textSize="40sp"

android:layout_weight="1"

/>

<TextView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:textColor="#0f0"

android:background="#00f"

android:text="中間"

android:textSize="40sp"

android:layout_weight="1"

/>

<TextView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:textColor="#0f0"

android:background="#f00"

android:text="下面"

android:textSize="40sp"

android:layout_weight="1"

/>

</LinearLayout>

---->子控件高度 = 子控件原本高度 + (父控件LinearLayout高度 - 所有子控件高度之和) * 子控件高度權重比

上面第個子控件TextView的高度

= 1屏高 + [ (1屏高 - 3屏高) * 1/(1+1+1) ]

= 1屏高 + [-2屏高*(1/3) ]

= 1屏高 - 2屏高*(1/3)

= 1屏高 - 2/3屏高

= 1/3 屏高

例2:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="//schemas.android.com/apk/res/android" 

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="left"

android:text="one"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:layout_weight="1.0"

android:text="two"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="right"

android:text="three"/>

</LinearLayout>

分析

**使用公式---->子控件高度 = 子控件原本高度 + (父控件LinearLayout高度 - 所有子控件高度之和) * 子控件高度權重比

**(1) one的高度 = one高度 + [1屏高 - (one高度+two高度+three高度) ] * 0/(1+0+0)

= one高度 + 0

= one高度

(2)two的高度 = two高度 +[1屏高 - (one高度+two高度+three高度) ] * 1/(1+0+0)

= one高度 +[1屏高 - (one高度+one高度+one高度) ]

= one高度 +[1屏高 - 3one高度]

= 1屏高 - 2one高度

(3)three的高度 = one高度 + [1屏高 - (one高度+two高度+three高度) ] * 0/(1+0+0)

= one高度 + 0

' = one高度 = three高度

例3:

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

<TextView

android:background="#ff0000"

android:layout_width="**"

android:layout_height="wrap_content"

android:text="1"

android:textColor="@android:color/white"

android:layout_weight="1"/>

<TextView

android:background="#cccccc"

android:layout_width="**"

android:layout_height="wrap_content"

android:text="2"

android:textColor="@android:color/black"

android:layout_weight="2" />

<TextView

android:background="#ddaacc"

android:layout_width="**"

android:layout_height="wrap_content"

android:text="3"

android:textColor="@android:color/black"

android:layout_weight="3" />

</LinearLayout>

分析:

**使用公式子控件寬度 = 子控件原本寬度 + (父控件LinearLayout寬度 - 所有子控件寬度之和) * 子控件寬度權重比

** 當三個android:layout_width="**"都改為android:layout_width="wrap_content"時, 三個TextView的原本寬度一樣寬,該寬度下面使用X表示

第1個TextView寬度 = X + (1屏寬 - 3X) * 1/(1+2+3)

= X + (1屏寬 - 3X) * 1/6

=X- (1/2)X + (1/6)屏寬

= (1/2)X + (1/6)屏寬

第2個TextView寬度 = X+ (1屏寬 - 3X) * 2/(1+2+3)

= X+ (1屏寬 - 3X) * 1/3

= X- X+ (1/3)屏寬

= (1/3)屏寬

第3個TextView寬度 = X+ (1屏寬 - 3X) * 3/(1+2+3)

= X + (1屏寬 - 3X) * 1/2

= X- (3/2)X + (1/2)屏寬

= (1/2)屏寬 - (1/2)X

當三個android:layout_width="**"都改為android:layout_width="fill_parent"時, 并把原android:layout_weight改為 1, 2, 2

三個TextView的原本寬度一樣寬,該寬度都是一個屏寬, 使用W表示

第1個TextView寬度 = W + (W - 3W) * 1/(1+2+2)

= W + (W - 3W) * 1/5

= W - 2W * (1/5)

= W-(2/5)W

= (3/5)W

第2個TextView寬度 = W + (W - 3W) * 2/(1+2+2)

= W + (W - 3W) * 2/5

= W - 2W * (2/5)

= W-(4/5)W

= (1/5)W

第3個TextView寬度 = W + (W - 3W) * 2/(1+2+2)

= W + (W - 3W) * 2/5

= W - 2W * (2/5)

= W-(4/5)W

= (1/5)W

當三個android:layout_width="**"都改為android:layout_width="fill_parent"時, 并把原android:layout_weight改為 1, 2, 3

三個TextView的原本寬度一樣寬,該寬度都是一個屏寬, 使用1W表示

第1個TextView寬度 = W + (W - 3W) * 1/(1+2+3)

=W + (W - 3W) * 1/6

=W - 2W * (1/6)

=W-(1/3)W

= (2/3)W

第2個TextView寬度 = W + (W - 3W) * 2/(1+2+3)

= W + (W - 3W) * 2/6

= W - 2W * (1/3)

= W-(2/3)W

= (1/3)W

第3個TextView寬度 = W + (W - 3W) * 3/(1+2+3)

= W + (W - 3W) * 1/2

= W - 2W * (1/2)

= W- W

=0

上一篇:Linux 設備樹詳解

下一篇:淺談C語言中的浮點數

熱點文章推薦
華清學員就業榜單
高薪學員經驗分享
熱點新聞推薦
前臺專線:010-82525158 企業培訓洽談專線:010-82525379 院校合作洽談專線:010-82525379 Copyright © 2004-2022 北京華清遠見科技集團有限公司 版權所有 ,京ICP備16055225號-5京公海網安備11010802025203號

回到頂部

主站蜘蛛池模板: 国产激情免费视频 | 伊人久久视频在线 | 内射精品无码中文字幕 | 亚洲色最新高清AV网站 | 日韩无套内射视频6 | 一女4p三黑人免费视频 | 中日韩精品视频一区二区三区 | 日韩性生活一级片 | 中国熟妇VDEOS免费视频 | 无码国产69精品久久久久孕妇 | 18未满禁止观看黄瓜视频 | 中国丰满熟妇XXXX | 大胆GOGO无码不卡播放 | 日本视频二区 | 日本草草视频 | 国产AV无码专区亚洲AV潘金链 | 日本成人免费在线观看 | 1区2区3区4区产品乱码入口 | 成在线人免费无码高潮喷水 | 99视频有精品视频 | 久久久国产精品VA麻豆 | 一二三四视频社区5在线高清 | 人人妻人人做人人爽精品 | 夜夜揉揉日日人人青青 | 一级少妇女片 | 亚洲精品无码成人网站 | 午夜男女爽爽爽免费播放 | 色婷婷五月综合亚洲小说 | mm1313亚洲精品无码又大又粗 | 色吊丝AV中文字幕 | 国产激情怍爱视频在线观看 | 3级毛片在线观看 | 亚洲AV永久无码天堂网毛片 | 蜜桃成人免费视频在线播放 | 一女三男做2爱A片免费 | www国产com | 欧美另类在线制服丝袜国产 | 久久亚洲中文字幕无码 | 日韩亚无码一区二区三区 | 性少妇freesexvideos强迫 | 亚洲欧美闷骚影院 |