溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

android基礎之LinearLayout布局

發布時間:2020-07-13 00:55:12 來源:網絡 閱讀:495 作者:hagar 欄目:移動開發

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"  

    />

<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基礎之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基礎之LinearLayout布局

Layout_weight屬性:

所有的組件都有這個屬性,不設置的情況下默認為0,其屬性表示當前有多大視圖就占據多大視圖

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

示例代碼如下:

<?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基礎之LinearLayout布局

線性布局中常用的屬性:

1:gravity:每個組件默認其值為左上角對齊。這個屬性可以調整組件對齊方式比如如何向左。向右或者居中對齊等、

2:padding邊距的填充,也稱內邊距.指的是當前布局與包含的組件之間的邊距

android:paddingTop

android:paddingBottom

android:paddingLeft

android:paddingRight

android:padding表示周圍四方向個邊距統一調整

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

android:layout_marginTop

android:layout_marginBottom

android:layout_marginLeft

android:layout_marginRight

android:layout_margin表示設置四方向邊距統一調整

一個比較綜合的例子:

<?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基礎之LinearLayout布局

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女