LinearLayout线性布局
元素属性:
gravity="left"(是本元素所有子元素的对齐方式,设置在父元素上,可设置多个值,多个值用|符号隔开
layout_gravity (子元素在父元素的对齐方式,设置在子元素上)
orientation="vertical" 时, 只有水平方向的设置才起作用。垂直分布
orientation="horizontal" 时, 只有垂直方向的设置才起作用。水平分布wrap_parent:匹配自身长宽
match_parent:匹配父长宽,也就是整个显示屏幕
fill_parent:填充屏幕长宽
实现关键点:(线性布局嵌套,layout_weight权重比)
<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="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.10"
android:gravity="left"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
android:layout_marginTop="400dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2.49"
android:gravity="center"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮3"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.33"
android:gravity="right"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮4"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮5"
android:layout_marginTop="400dp"/>
</LinearLayout>
</LinearLayout>
注:在使用layout_weight权重分比时,多注意值大小的分配。