欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android線性布局與相對布局的實(shí)現(xiàn)

 更新時(shí)間:2022年02月14日 14:15:36   作者:少年白馬  
大家好,本篇文章主要講的是Android線性布局與相對布局的實(shí)現(xiàn),感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下

線性布局(LinearLayout)

名字含義
android:id設(shè)置一個(gè)id方便使用
android:layout_width寬度
android:layout_height高度
android:background設(shè)置背景顏色
android:layout_margin設(shè)置外邊距
android:layout_padding設(shè)置內(nèi)邊距
android:orientation設(shè)置方向(水平或者垂直)

練習(xí)代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/ll_1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:orientation="vertical"
        android:background="#000000"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="50dp"
        android:paddingBottom="10dp">

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FF0033"/>

    </LinearLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="horizontal"
        android:background="#0066FF"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp">

        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#000000"
            android:layout_weight="1"/>
        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#FF0033"
            android:layout_weight="1"/>
        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#55AA99"
            android:layout_weight="1"/>


    </LinearLayout>

</LinearLayout>

實(shí)現(xiàn)效果

請?zhí)砑訄D片描述

相對布局(RelativeLayout)

最常用屬性

名字含義
android:layout_toLeftOf在什么的左邊
android:layout_toRightOf在什么的右邊
android:layout_alignBottom跟什么底部對齊
android:layout_alignParentBottom與父控件底部對齊
android:layout_below在什么的底部

樣例效果

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/view_1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#000000" />

    <View
        android:id="@+id/view_2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_below="@id/view_1"
        android:background="#FF0033" />

    <LinearLayout
        android:id="@+id/ll_1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_below="@id/view_2"
        android:background="#0066FF"
        android:orientation="horizontal"
        android:padding="15dp">

        <View
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#FF0033" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:padding="15dp">

            <View
                android:id="@+id/view_3"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#FF9900"/>
            <View
                android:id="@+id/view_4"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#FF9900"
                android:layout_toRightOf="@id/view_3"
                android:layout_marginLeft="10dp"/>

        </RelativeLayout>
    </LinearLayout>


</RelativeLayout>

實(shí)現(xiàn)效果

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機(jī)制,建議將圖片保存下來直接上傳(img-QfAGp5xf-1644810525369)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220212100319575.png)]

總結(jié)

到此這篇關(guān)于Android線性布局與相對布局的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Android布局內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論