LinearLayout布局簡單介紹

LinearLayout android中常用的線性布局

成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比嵩縣網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式嵩縣網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋嵩縣地區(qū)。費用合理售后完善,10余年實體公司更值得信賴。

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

下面對LinearLayout的幾個屬性做簡單的介紹

1、android:orientation屬性:

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

vertical:垂直排列

horizontal:水平排列

舉個例子:

比如我們要在一個界面中做一個3x3

即3行3列的按鈕

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

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

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

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

如android:layout_marginTop="20dp"即距離上個控件20dp

3、控件按比例排列

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

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

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

如在一行顯示兩個控件一個TextView、另一個EditText

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

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

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

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

以上即是LZ對LinearLayout的簡單理解

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

貼出主要布局代碼

<?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布局簡單介紹

新聞名稱:LinearLayout布局簡單介紹
分享鏈接:http://www.muchs.cn/article46/geheeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)品牌網(wǎng)站建設(shè)、ChatGPT搜索引擎優(yōu)化、響應(yīng)式網(wǎng)站、電子商務(wù)

廣告

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

成都app開發(fā)公司