Android中LinearLayout布局的常用属性总结

2019-12-10 18:19:35丽君

透过 OR 运算子组合重心

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:gravity="top|right">

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1" />

</LinearLayout>

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:gravity="bottom|left">

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1" />

</LinearLayout>

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:gravity="center_vertical|center_horizontal">

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1" />

</LinearLayout>

比例分配

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal">

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1"

    android:layout_weight="1"/>

</LinearLayout>

  • android:layout_weight
  • 子元件或子框架的比重。
  • LinearLayout 下的子元件或子框架,才能设定这项属性。

    等比例分配