Android studio簡單布局之view基本屬性


本人屬於自學上路,目前是在入門階段,所以有些內容實質性比較少,請各位大佬多多包涵。

視圖view的基本屬性:

layout_margin:定義視圖與周圍視圖之間的空白距離

layout_padding:是指當前視圖與內部內容的距離

線性布局LinearLayout

  layout_gravity:指定該視圖與上級視圖的對齊方式

  gravity:指定布局內容視圖與本視圖的對齊方式

附上實例代碼與運行結果:

<?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:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:background="#ffff99"
    android:orientation="horizontal"
    android:padding="0dp">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:layout_weight="1"
        android:layout_gravity="bottom"
        android:gravity="left"
        android:background="#ff0000"
        android:layout_margin="20dp"
        android:padding="20dp"
        android:orientation="vertical"
        >

        <View
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#0000ff"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:layout_weight="1"
        android:layout_gravity="top"
        android:gravity="right"
        android:background="#ff0000"
        android:layout_margin="10dp"
        android:padding="10dp"
        android:orientation="vertical"
        >

        <View
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#0000ff"/>

    </LinearLayout>
</LinearLayout>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM