在 Jetpack Compose 中,是否有类似于 XML 中使用 weights 的 ConstraintLayout chains 的方法:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/first"
android:layout_width="0dp"
android:layout_height="48dp"
android:background="#caf"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/start"
app:layout_constraintHorizontal_weight="6"/>
<View
android:id="@+id/second"
android:layout_width="0dp"
android:layout_height="48dp"
android:background="#fac"
app:layout_constraintLeft_toRightOf="@+id/first"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_weight="4"/>
</android.support.constraint.ConstraintLayout>
目前,ConstraintLayoutScope
和ConstraintScope
均不提供权重功能。 ConstraintLayoutScope
提供createHorizontalChain(vararg elements: ConstraintLayoutReference, chainStyle: ChainStyle)
(或相应的createVerticalChain
),但没有为单个元素设置权重的选项。
使用指南线、障碍物和其他所有集成的元素后,我感觉还缺少了一些重要的东西。是否有一种方法可以在链中使用权重或模拟它们的行为?我不能仅为一个元素指定固定宽度,因为ConstraintLayout的宽度必须匹配整个屏幕。
注意:我知道新的Jetpack Compose ConstraintLayout对于像Android View ConstraintLayout那样的复杂嵌套布局结构并没有性能优势。我也知道Row和Column提供权重功能,但在我的情况下,我必须使用ConstraintLayout(原因)