LinearLayout布局簡單介紹-創(chuàng)新互聯(lián)

LinearLayout android中常用的線性布局

公司主營業(yè)務(wù):成都做網(wǎng)站、成都網(wǎng)站制作、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)建站是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)建站推出獨(dú)山子免費(fèi)做網(wǎng)站回饋大家。

可以根據(jù)屏幕的大小自動(dòng)調(diào)節(jié)控件

下面對(duì)LinearLayout的幾個(gè)屬性做簡單的介紹

1、android:orientation屬性:

即排列方式,可以選擇橫排或豎排(horizontal,vertical)

vertical:垂直排列

horizontal:水平排列

舉個(gè)例子:

比如我們要在一個(gè)界面中做一個(gè)3x3

即3行3列的按鈕

那么在主LinearLayout中我們通常用垂直布局即(android:orientation="vertical")

在主框架中我們再添加三個(gè)子框架,子框架中采用水平布局(android:orientation="horizontal")

2、控制子框架之間的距離

通常用 android:layout_margin..(包括上下左右)

如android:layout_marginTop="20dp"即距離上個(gè)控件20dp

3、控件按比例排列

有些時(shí)候,對(duì)于某些空間我們不想讓其占據(jù)太多位置,當(dāng)然對(duì)于固定的機(jī)型屏幕可以設(shè)置給它固定的

大小,但是屏幕適配是不合格的

在這里我們就需要用到了android:layout_weight=""屬性

如在一行顯示兩個(gè)控件一個(gè)TextView、另一個(gè)EditText

我們需要讓EditText占據(jù)更多的空間這里我們選擇1:2

于是在TextView的屬性中我們設(shè)置為(android:layout_weight="1")

同樣在EditText中設(shè)置屬性為(android:layout_weight="2")

前提是該子框架中只有這兩個(gè)控件。

以上即是LZ對(duì)LinearLayout的簡單理解

如有不懂或錯(cuò)誤之處,歡迎給出建議?。?!

貼出主要布局代碼

<?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="vertical" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/name" />
        <EditText
            android:id="@+id/editText1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2" >
        </EditText>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/num" />
        <EditText
            android:id="@+id/editText2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:ems="10" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />
        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />
    </LinearLayout>
</LinearLayout>

LinearLayout布局簡單介紹

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)站標(biāo)題:LinearLayout布局簡單介紹-創(chuàng)新互聯(lián)
分享路徑:http://muchs.cn/article0/dieiio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、搜索引擎優(yōu)化、外貿(mào)建站、關(guān)鍵詞優(yōu)化品牌網(wǎng)站建設(shè)、ChatGPT

廣告

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

營銷型網(wǎng)站建設(shè)