Android线性布局LinearLayout

1. 排列方式

  • 纵向:android:orientation="vertical"
  • 横向:android:orientation="horizontal"
    系统默认采用横向布局

2. 对齐方式

  两种设置边距的方式,分别是 

  1. android:paddingStart="150dp" //和左侧的边距

  2. android:paddingTop="50dp" //和顶部的边距

3. 权重

   线性布局中可以规定控件的权重,通过android:layout_weight=""实现。

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


    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="#00ff00"
        android:layout_weight="1"/>

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="#0000ff"
        android:layout_weight="2"/>

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="#ff0000"
        android:layout_weight="3"/>

</LinearLayout>

当子权重大于总权重  先到先得原则:

效果如图:

猜你喜欢

转载自blog.csdn.net/I_am_a_loser/article/details/120150223