1.LinearLayout—线性布局

  1. <LinearLayout
  2. android:orientation="vertical"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <Button
  6. android:text="按钮"
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content" />
  9. </LinearLayout>
  1. android:layout_width //定义width
  2. android:layout_height //定义height
  3. math_parent //继承父组件的width、height
  4. wrap_content //组件实际的大小

1.1线性布局中可以嵌套

  1. //两个并排显示
  2. <LinearLayout
  3. android:background="#333"
  4. android:orientation="horizontal"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. >
  8. <LinearLayout
  9. android:background="#333"
  10. android:layout_weight="1"
  11. android:layout_width="0dp"
  12. android:layout_height="match_parent"></LinearLayout>
  13. <LinearLayout
  14. android:background="#fff"
  15. android:layout_weight="1"
  16. android:layout_width="0dp"
  17. android:layout_height="match_parent"></LinearLayout>
  18. </LinearLayout>

2.GridLayout

  1. //一行四个
  2. <GridLayout
  3. android:columnCount="4"
  4. android:rowCount="3"
  5. android:layout_width="match_parent"
  6. android:layout_height="300dp"
  7. tools:context="MissingConstraints"
  8. >
  9. <Button />
  10. <Button />
  11. <Button />
  12. <Button />
  13. <Button />
  14. <Button />
  15. <Button />
  16. <Button />
  17. </GridLayout>