linearLayout即线性布局,即一行展开或一列展开,也可以镶套,重要的方法
是andriod:orentation方向。
xml代码如下
<?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">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button1"></Button>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button2"></Button>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button3"></Button>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button4"></Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button5"></Button>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button6"></Button>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button7"></Button>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button8"></Button>
</LinearLayout>
</LinearLayout>
效果如下: