最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android布局之LinearLayout線性布局

 更新時間:2015年12月31日 09:51:34   作者:會飛的一只狼  
LinearLayout是線性布局控件:要么橫向排布,要么豎向排布,下面通過本篇文章給大家介紹Android布局之LinearLayout線性布局,涉及到android linearlayout 布局相關知識,對本文感興趣的朋友一起學習吧

LinearLayout是線性布局控件:要么橫向排布,要么豎向排布

常用屬性:

android:gravity------------設置的是控件自身上面的內容位置

android:layout_gravity-----設置控件本身相對于父控件的顯示位置

android:layout_weight----- 給控件分配剩余空間

先給大家展示一下導圖:


知識點詳解(演示效果方便組件沒有設置id)

(1)gravity和Layout_gravity

android:gravity 屬性是對該view中內容的限定.比如一個button 上面的text. 你可以設置該text 相對于view的靠左,靠右等位置.

android:layout_gravity是用來設置該view相對與父view 的位置.比如一個button 在linearlayout里,你想把該button放在linearlayout里靠左、靠右等位置就可以通過該屬性設置.

(2)weight權重(以水平為例)

 ?。╝)當width = 0或者 width = wrap_content的時候,按照權重比例計算!:2: 3

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/text1" 
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_red_dark"
android:text="Text1"/>
<TextView
android:id="@+id/text2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@android:color/holo_blue_bright"
android:text="Text2"/>
<TextView
android:id="@+id/text3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_weight="3"
android:text="Text3"/>
</LinearLayout> 

 ?。╞)當width = fill_parent/match_parent的時候

    第一步:當三個都為match_parent的時候屏幕只有一個 1 -3 = -2;

    第二步:計算每個TextView占有的比例 1/6,2/6,3/6;

    第三步: 1 -2*1/6 = 2/3; 1 - 2*2/6 = 1/3; 1 - 2*3/6 = 0;

    第四步:2:1:0

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_red_dark"
android:text="Text1"
android:gravity="center"
android:textSize="40sp"/>
<TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@android:color/holo_blue_bright"
android:text="Text2"
android:gravity="center"
android:textSize="40sp"/>
<TextView
android:id="@+id/text3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_weight="3"
android:text="Text3"
android:gravity="center"
android:textSize="40sp"/>
</LinearLayout> 

(3)分割線

<View
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:layout_width="3"
android:layout_height="match_parent" 
android:background="#ff00ee" /> 

案例(底部導航)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80sp"
android:layout_gravity="bottom"
android:background="@android:color/holo_purple">
<LinearLayout
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:layout_width="3"
android:layout_height="match_parent"
android:background="#ff00ee" />
<LinearLayout
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
android:textSize="20sp"/>
</LinearLayout>
<View
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:layout_width="3"
android:layout_height="match_parent"
android:background="#ff00ee" />
<LinearLayout
android:layout_width="0sp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three"
android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

以上內容給大家介紹了Android布局之LinearLayout線性布局的相關知識,希望大家喜歡。

相關文章

  • 基于Android實現(xiàn)一個簡易音樂播放器

    基于Android實現(xiàn)一個簡易音樂播放器

    在Android平臺上開發(fā)一個音樂播放器是一項常見的任務,這涉及到對音頻文件的處理、用戶界面設計以及多媒體框架的運用,本項目基于樣例代碼進行擴展,雖然功能相對簡單,但包含了Android音樂播放器開發(fā)的核心知識點,需要的朋友可以參考下
    2024-08-08
  • Flutter學習之構建、布局及繪制三部曲

    Flutter學習之構建、布局及繪制三部曲

    這篇文章主要給大家介紹了關于Flutter學習之構建、布局及繪制三部曲的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Flutter具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-04-04
  • Android自定義View實現(xiàn)多邊形統(tǒng)計圖示例代碼

    Android自定義View實現(xiàn)多邊形統(tǒng)計圖示例代碼

    這篇文章主要給大家介紹了關于Android自定義View如何實現(xiàn)多邊形統(tǒng)計圖的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
    2018-01-01
  • Android 判斷是否是是全漢字、全字母、全數字、數字和字母等(代碼)

    Android 判斷是否是是全漢字、全字母、全數字、數字和字母等(代碼)

    這篇文章主要介紹了Android 判斷是否是是全漢字、全字母、全數字、數字和字母等的實例代碼,需要的朋友可以參考下
    2016-12-12
  • Flutter實現(xiàn)切換應用時隱藏應用預覽

    Flutter實現(xiàn)切換應用時隱藏應用預覽

    如果您要顯示敏感數據,例如錢包金額,或者只是當登錄表單顯示插入的密碼清晰時,當您不在應用程序中時,您必須隱藏敏感數據。本文將利用Flutter實現(xiàn)切換應用時隱藏應用預覽,需要的可以參考一下
    2022-06-06
  • Android生成條形碼和二維碼功能

    Android生成條形碼和二維碼功能

    隨著移動互聯(lián)網的普及以及智能終端設備的廣泛應用,移動支付變得越來越便捷,通過掃描二維碼代替?zhèn)鹘y(tǒng)的刷卡行為。這篇文章給大家介紹Android生成條形碼和二維碼功能,需要的朋友參考下吧
    2019-10-10
  • android獲取當前手機號示例程序

    android獲取當前手機號示例程序

    這篇文章主要介紹了android如何獲取當前手機號的方法,大家參考使用吧
    2013-11-11
  • Android AutoCompleteTextView控件使用實例

    Android AutoCompleteTextView控件使用實例

    AutoCompleteTextView這個控件用于輸入框的自動完成提示,非常適合搜索框等。它本質上是個EditText,實際上它也是從EditText繼承的,使用起來也十分簡單
    2014-04-04
  • Android的ListView多選刪除操作實現(xiàn)代碼

    Android的ListView多選刪除操作實現(xiàn)代碼

    這篇文章主要為大家詳細介紹了Android的ListView多選刪除操作實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android TreeView實現(xiàn)帶復選框樹形組織結構

    Android TreeView實現(xiàn)帶復選框樹形組織結構

    這篇文章主要為大家詳細介紹了Android TreeView實現(xiàn)帶復選框樹形組織結構,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07

最新評論

格尔木市| 太康县| 介休市| 磴口县| 永丰县| 保山市| 壶关县| 锦州市| 额尔古纳市| 瑞昌市| 西华县| 新乡市| 黄山市| 嘉祥县| 彭阳县| 嘉峪关市| 建湖县| 凤山市| 怀柔区| 体育| 彩票| 合作市| 高州市| 扶余县| 称多县| 淳安县| 什邡市| 石景山区| 咸丰县| 嵊州市| 瓮安县| 四子王旗| 陇川县| 常山县| 沈丘县| 当雄县| 九龙城区| 原阳县| 汝城县| 高州市| 三台县|