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

Android布局控件之常用linearlayout布局

 更新時間:2016年01月15日 16:42:48   投稿:mrr  
LinearLayout是線性布局控件,它包含的子控件將以橫向或豎向的方式排列,按照相對位置來排列所有的widgets或者其他的containers,超過邊界時,某些控件將缺失或消失

LinearLayout是線性布局控件,它包含的子控件將以橫向或豎向的方式排列,按照相對位置來排列所有的widgets或者其他的containers,超過邊界時,某些控件將缺失或消失。因此一個垂直列表的每一行只會有一個widget或者是container,而不管他們有多寬,而一個水平列表將會只有一個行高(高度為最高子控件的高度加上邊框高度)。LinearLayout保持其所包含的widget或者是container之間的間隔以及互相對齊(相對一個控件的右對齊、中間對齊或者左對齊)。

xml屬性

android:baselineAligned:是否允許用戶調(diào)整它內(nèi)容的基線。

android:baselineAlignedChildIndex:當(dāng)一個線性布局與另一個布局是按基線對齊的一部分,它可以指定其內(nèi)容的基線對齊方式。

android:gravity:指定如何在該對象中放置此對象的內(nèi)容(x/y坐標(biāo)值)。

android:orientation:設(shè)置它內(nèi)容的對其方向(橫向/豎向)。

gravity 這個英文單詞是重心的意思,在這里就表示??课恢玫囊馑?。

android:layout_gravity 和 android:gravity 的區(qū)別

從名字上可以看到,android:gravity是對元素本身說的,元素本身的文本顯示在什么地方靠著換個屬性設(shè)置,不過不設(shè)置默認是在左側(cè)的。

android:layout_gravity是相對與它的父元素說的,說明元素顯示在父元素的什么位置。

比如說button:android:layout_gravity 表示按鈕在界面上的位置。 android:gravity表示button上的字在button上的位置。

可選值

這兩個屬性可選的值有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。

而且這些屬性是可以多選的,用“|”分開。

默認這個的值是:Gravity.LEFT

LinearLayout還支持為其包含的widget或者是container指定填充權(quán)值。好處就是允許其包含的widget或者是container可以填充屏幕上的剩余空間。這也避免了在一個大屏幕中,一串widgets或者是containers擠成一堆的情況,而是允許他們放大填充空白。剩余的空間會按這些widgets或者是containers指定的權(quán)值比例分配屏幕。默認的 weight 值為0,表示按照widgets或者是containers實際大小來顯示,若高于0的值,則將Container剩余可用空間分割,分割大小具體取決于每一個widget或者是container的layout_weight及該權(quán)值在所有widgets或者是containers中的比例。例如,如果有三個文本框,其中兩個指定的權(quán)值為1,那么,這兩個文本框?qū)⒌缺壤胤糯?,并填滿剩余的空間,而第三個文本框不會放大,按實際大小來顯示。如果前兩個文本框的取值一個為2,一個為1,顯示第三個文本框后剩余的空間的2/3給權(quán)值為2的,1/3大小給權(quán)值為1的。也就是權(quán)值越大,重要度越大。

如果LinearLayout包含子LinearLayout,子LinearLayout之間的權(quán)值越大的,重要度則越小。如果有LinearLayout A包含LinearLayout C,D,C的權(quán)值為2,D的權(quán)值為1,則屏幕的2/3空間分給權(quán)值為1的D,1/3分給權(quán)值為2的C。在LinearLayout嵌套的情況下,子LinearLayout必須要設(shè)置權(quán)值,否則默認的情況是未設(shè)置權(quán)值的子LinearLayout占據(jù)整個屏幕

用linearlayout完成這樣的布局效果,這樣的布局還是比較常用的,具體的xml代碼如下:

1.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:baselineAligned="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕1"
/> 
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕2"
/> 
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕3"
/> 
</LinearLayout>

2.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:baselineAligned="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕1"
/> 
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕2"
/> 
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕3"
/> 
</LinearLayout>

3.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:baselineAligned="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕1"
/> 
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕2"
/> 
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕3"
/> 
</LinearLayout>

相關(guān)文章

  • Android酷炫動畫效果之3D星體旋轉(zhuǎn)效果

    Android酷炫動畫效果之3D星體旋轉(zhuǎn)效果

    本文要實現(xiàn)的3D星體旋轉(zhuǎn)效果是從CoverFlow演繹而來,不過CoverFlow只是對圖像進行轉(zhuǎn)動,我這里要實現(xiàn)的效果是要對所有的View進行類似旋轉(zhuǎn)木馬的轉(zhuǎn)動
    2018-05-05
  • Android實現(xiàn)二級列表購物車功能

    Android實現(xiàn)二級列表購物車功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)二級列表購物車功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android使用自定義View繪制漸隱漸現(xiàn)動畫

    Android使用自定義View繪制漸隱漸現(xiàn)動畫

    這篇文章主要介紹了Android使用自定義View繪制漸隱漸現(xiàn)動畫效果的相關(guān)內(nèi)容,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-09-09
  • Android 實現(xiàn)無網(wǎng)絡(luò)傳輸文件的示例代碼

    Android 實現(xiàn)無網(wǎng)絡(luò)傳輸文件的示例代碼

    本篇文章主要介紹了Android 實現(xiàn)無網(wǎng)絡(luò)傳輸文件的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • Android自動測試工具Monkey

    Android自動測試工具Monkey

    Monkey是Android中的一個命令行工具,可以運行在模擬器里或?qū)嶋H設(shè)備中。它向系統(tǒng)發(fā)送偽隨機的用戶事件流(如按鍵輸入、觸摸屏輸入、手勢輸入等),實現(xiàn)對正在開發(fā)的應(yīng)用程序進行壓力測試。Monkey測試是一種為了測試軟件的穩(wěn)定性、健壯性的快速有效的方法
    2016-01-01
  • Android RecyclerView設(shè)置下拉刷新的實現(xiàn)方法

    Android RecyclerView設(shè)置下拉刷新的實現(xiàn)方法

    這篇文章主要介紹了Android RecyclerView設(shè)置下拉刷新的實現(xiàn)方法,希望通過本文通過SwipeRefreshLayout方式實現(xiàn)下拉刷新,需要的朋友可以參考下
    2017-10-10
  • Android超詳細講解組件ScrollView的使用

    Android超詳細講解組件ScrollView的使用

    本節(jié)帶來的是Android基本UI控件中的第十個:ScrollView(滾動條),或者我們應(yīng)該叫他?豎直滾動條,對應(yīng)的另外一個水平方向上的滾動條:HorizontalScrollView,先讓我們來了解ScrollView
    2022-03-03
  • Android四大組件之Activity深入解讀生命周期

    Android四大組件之Activity深入解讀生命周期

    雖然說我們天天都在使用Activity,但是你真的對Activity的生命機制完全了解了嗎?Activity的生命周期方法只有七個,但是其實那只是默認的情況。也就是說在其他情況下,Activity的生命周期可能不會是按照我們以前所知道的流程,這就要說到Activity的啟動模式
    2022-07-07
  • Android DrawerLayout布局與NavigationView導(dǎo)航菜單應(yīng)用

    Android DrawerLayout布局與NavigationView導(dǎo)航菜單應(yīng)用

    這篇文章主要介紹了Android DrawerLayout抽屜布局與NavigationView導(dǎo)航菜單應(yīng)用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2023-01-01
  • Android下拉列表spinner的實例代碼

    Android下拉列表spinner的實例代碼

    這篇文章主要為大家詳細介紹了Android下拉列表spinner的實例代碼。感興趣的小伙伴們可以參考一下
    2016-05-05

最新評論

广河县| 鹰潭市| 高雄市| 漯河市| 米泉市| 六安市| 安仁县| 新竹县| 蚌埠市| 沭阳县| 洛宁县| 普陀区| 渝北区| 连山| 肥城市| 尼勒克县| 儋州市| 翼城县| 阿勒泰市| 海阳市| 尼玛县| 延川县| 西平县| 广河县| 济宁市| 侯马市| 和平县| 罗源县| 米泉市| 广安市| 台安县| 云梦县| 台湾省| 新邵县| 石棉县| 桐乡市| 揭西县| 新河县| 海安县| 永清县| 正安县|