18.9.11-线性布局

2018-09-11  本文已影响0人  VGSemir

线性布局

常用属性

  1. id: 相当于标识符
  2. background
  3. padding: 内边距 margin: 外边距
  4. gravity: 设置相对位置
  5. orientation: 排列方向

Demo:

<?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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <!--
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
     -->

    <LinearLayout
        android:id="@+id/ll_1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#109890"
        android:orientation="vertical"
        android:padding="20dp">
        <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:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:background="#0997F7"
        android:orientation="horizontal">

        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#808080"
            android:layout_weight="1"/>
        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#CC33CC"
            android:layout_weight="1"/>

    </LinearLayout>
    
</LinearLayout>
上一篇 下一篇

猜你喜欢

热点阅读