可以贴一下代码看看
不能新写回答,补充:
左、中、右对应的三个LinearLayout需要用一个父级LinearLayout包裹,并设置orientation属性为horitantal
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="top">
<Button
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="上" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="300dp"
android:orientation="left_horizontal"
android:layout_gravity="fill_vertical"
android:layout_weight="0">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="左" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="400dp"
android:layout_weight="1"
android:orientation="center_horizontal"
android:layout_gravity="center"
>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="中"/>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:orientation="right_horizontal"
android:layout_gravity="right"
android:layout_weight="0">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="右"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_gravity="bottom">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:text="下" />
</LinearLayout>
</LinearLayout>
```
android:layout_weight 这个是权重属性,假如一个布局下有多个控件,那么每个控件权重为1,那这些控件就要会按照1:1:1来进行宽度或者高度来分配,如果这些控件的父布局是垂直排序,这些控件就高度1:1:1平分父布局的高度,不能设置为0,
如果水平排序
android:orientation="horizontal"
设置了权重,android:layout_width就要设置为0dp,因为水平方向的宽度用权重来分配
如果垂直排序
android:orientation="vertical"
设置了权重,android:layout_height就要设置为0dp,因为垂直方向的高度用权重来分配
我看你发的布局文件好多都设置错误了,权重如果不用就不要设置了,而且最关键的一点,你整体应该是垂直排序的,所以根布局下,应该加android:orientation="vertical"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
两层线性布局
第一层为竖向
第二层为横向(中间部分)
要均分,横向宽度为0 weight为1,竖向,高度为0,weight为1
不好控制就用TableLayout