能否在Jetpack Compose中设置权重?例如,我想以这样的方式设置它:一个项目的权重为布局的1/3,另一个项目占用剩余的2/3。
在XML / ViewGroup风格中,您可以使用LinearLayout和ConstraintLayout实现此目的。但是,令人失望的是,使用Jetpack Compose似乎不可能。 示例: 在ConstraintLayout中,可以按以下方式完成这个问题:
在XML / ViewGroup风格中,您可以使用LinearLayout和ConstraintLayout实现此目的。但是,令人失望的是,使用Jetpack Compose似乎不可能。 示例: 在ConstraintLayout中,可以按以下方式完成这个问题:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<View
android:layout_width="0dp"
android:layout_height="100dp"
android:id="@+id/red"
android:background="@color/red"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/blue"
app:layout_constraintHorizontal_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="100dp"
android:id="@+id/blue"
android:background="@color/blue"
app:layout_constraintStart_toEndOf="@id/red"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="2"/>
</androidx.constraintlayout.widget.ConstraintLayout>
在LinearLayout中,可以通过以下方式来实现:
<?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:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="100dp"
android:id="@+id/red"
android:background="@color/red"
android:layout_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="100dp"
android:id="@+id/blue"
android:background="@color/blue"
android:layout_weight="2"/>
</LinearLayout>
我知道您可以使用表格来获取均匀分布的内容,但我想要一个不均匀的分布。