【发布时间】:2018-03-15 18:41:24
【问题描述】:
目前我正在使用嵌套的线性布局和嵌套的 weightsum 和布局权重来实现我在下面的屏幕截图中想要的。
但是,我确实注意到,正如 lint 警告所暗示的那样,我的一部过时手机有点慢。因为嵌套的权重总和似乎会阻碍设备的性能。
这是我目前的线性布局代码。我想实现所附的屏幕截图。有没有其他方法可以在不使用广泛嵌套的权重和的情况下实现它?我见过做类似事情的约束布局,但我如何实际使用它?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/title_layout"
android:weightSum="3"
android:orientation="vertical"
android:layout_above="@id/next">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:weightSum="3"
android:layout_weight="2">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#345678"
android:layout_weight="2">
</RelativeLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:weightSum="2"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:background="#3bcad5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
android:background="#3ca3d2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:weightSum="3"
android:layout_weight="1">
<RelativeLayout
android:background="#123456"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
android:background="#310911"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
android:background="#92F358"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
</RelativeLayout>
</LinearLayout>
</LinearLayout>
【问题讨论】: