天天看点

Android 开发笔记 1.0 LinearLayout线性布局

android:id  标识

android:id="@+id/name"  创建一个id

android:layout_width 宽度

android:layout_width="wrap_content"  自适应内容的宽度

android:layout_width="match_parent"   匹配父空间的宽度

android:layout_height  高度

android:layout_height="520dp"   单位使用 dp

android:margin 外边距

android:padding  内边距

    android:paddingLeft="20dp"   左内边距

    android:paddingRight    右内边距

    android:paddingTop    上内边距

    android:paddingBottom    下内边距

android:background  背景

android:background="#000000"    背景为黑色

android:orientation  方向

android:orientation="vertical"  垂直方向

android:orientation="horizontal"   水平方向

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.administrator.myapplication.MainActivity"
    android:background="#00ff55"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/L1"
        android:layout_width="200dp"
        android:layout_height="300dp"
        android:background="#000000"
        android:orientation="vertical"
        android:layout_margin="30dp"
        android:padding="20dp"
        >
        <LinearLayout
            android:id="@+id/L2"

            android:background="#ffffff"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/L3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:background="#ff0000"
        android:orientation="vertical"
        >



    </LinearLayout>

</LinearLayout>      
效果图
      
Android 开发笔记 1.0 LinearLayout线性布局

继续阅读