我想在xml中并排绘制三个正方形,以便它们水平填充屏幕(每边减去12 dp的边距)。根据this post似乎可以做这与表格布局混乱,但我想知道是否有更好的方法。这是我尝试使用嵌套LinearLayouts,这将矩形垂直地填满整个屏幕但除此之外没有什么我在寻找:Android - 在xml中绘制正方形
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12dp"
android:background="#ffffff"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/rectangle" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/rectangle" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/rectangle" >
</LinearLayout>
</LinearLayout>
父的LinearLayout应当包括机器人:wieghtSum =“3” –
按照[文档】( http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:weightSum)android:weightSum“定义了最大权重和,如果未指定,则通过添加所有子项的layout_weight来计算总和“。所以这不会有什么区别。 –