【发布时间】:2016-07-26 01:06:48
【问题描述】:
我们如何才能在约束布局中和在线性布局中一样节省空间?
比如下面的布局如果用约束写出来会变成什么样子?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="A"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="B"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="C"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="D"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
在约束布局中,我可以将A 和D 设置为边缘,将A←B→D 设置为33 偏置,将A←C→D 设置为66 偏置,以使每个元素之间的空间相等。
但该解决方案并不能真正扩展。
在约束布局中是否有适当的方法来做到这一点?
【问题讨论】:
-
你真的需要物品直接放在ConstraintLayout中,还是直接放到linearlayout中,然后把linearlayout放到ConstraintLayout中
-
@lionscribe ConstraintLayout 在这里,除其他外,进行平面设计并帮助提高性能。因此,我正在寻找一种以平面方式执行此操作的方法,无需任何其他嵌套布局。
标签: android android-layout android-constraintlayout