android基礎(chǔ)之LinearLayout布局

LinearLayout布局:

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到周寧網(wǎng)站設(shè)計(jì)與周寧網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類(lèi)型包括:網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、主機(jī)域名、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋周寧地區(qū)。

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

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

    xmlns:tools="http://schemas.android.com/tools"

    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="button1"  

    />

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button2"

    />

<Button

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:text="Button3"

    />

</LinearLayout>

android基礎(chǔ)之LinearLayout布局

LinearLayout布局的嵌套:

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

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

    xmlns:tools="http://schemas.android.com/tools"

    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="button1"  

    />

<LinearLayout android:orientation="vertical"

 android:layout_width="fill_parent"

 android:layout_height="wrap_content"

 >

 <Button

 android:text="Button2"   

 android:layout_width="wrap_content"

 android:layout_height="wrap_content"

/>

<Button

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:text="Button3"

    />

</LinearLayout>

</LinearLayout>

android基礎(chǔ)之LinearLayout布局

Layout_weight屬性:

所有的組件都有這個(gè)屬性,不設(shè)置的情況下默認(rèn)為0,其屬性表示當(dāng)前有多大視圖就占據(jù)多大視圖

如果其值高于0,則表示將父視圖中的可用空間進(jìn)行分割

示例代碼如下:

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

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

    xmlns:tools="http://schemas.android.com/tools"

    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="button1" 

    android:layout_weight="1" 

    />

<Button

    android:text="button4"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:layout_weight="1"

    />

</LinearLayout>

android基礎(chǔ)之LinearLayout布局

線性布局中常用的屬性:

1:gravity:每個(gè)組件默認(rèn)其值為左上角對(duì)齊。這個(gè)屬性可以調(diào)整組件對(duì)齊方式比如如何向左。向右或者居中對(duì)齊等、

2:padding邊距的填充,也稱(chēng)內(nèi)邊距.指的是當(dāng)前布局與包含的組件之間的邊距

android:paddingTop

android:paddingBottom

android:paddingLeft

android:paddingRight

android:padding表示周?chē)姆较騻€(gè)邊距統(tǒng)一調(diào)整

3:layout_margin:外邊距。指的是與其他組件之間的邊距。

android:layout_marginTop

android:layout_marginBottom

android:layout_marginLeft

android:layout_marginRight

android:layout_margin表示設(shè)置四方向邊距統(tǒng)一調(diào)整

一個(gè)比較綜合的例子:

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

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

    xmlns:tools="http://schemas.android.com/tools"

    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="button1" 

    android:layout_gravity="bottom" 

    android:paddingTop="10dp"

    />

<Button

    android:text="button4"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:layout_gravity="bottom"

    android:layout_marginLeft="50dp"

    android:layout_marginTop="30dp"

    />

<Button

    android:text="button2"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_gravity="bottom"  

    android:paddingLeft="60dp"

    android:paddingBottom="60dp"

   />

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button3"

    android:layout_gravity="right"

    />

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="button6"

    android:layout_gravity="right"

    android:layout_marginRight="40dp"

    android:layout_marginTop="40dp"

    />

</LinearLayout>

android基礎(chǔ)之LinearLayout布局

標(biāo)題名稱(chēng):android基礎(chǔ)之LinearLayout布局
URL鏈接:http://muchs.cn/article2/jcjdoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、網(wǎng)站改版、全網(wǎng)營(yíng)銷(xiāo)推廣、軟件開(kāi)發(fā)、關(guān)鍵詞優(yōu)化品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化