【发布时间】:2019-04-11 18:03:44
【问题描述】:
我有以下布局,我希望在LinearLayout 中具有与weightSum 和weight 相同的行为
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<LinearLayout
android:id="@+id/linear_layout_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:background="#a4c639"
android:thelayout_constraintHorizontal_weight="5"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Main information"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_layout_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#a4c639"
android:thelayout_constraintHorizontal_weight="5"
android:layout_marginStart="10dp"
app:layout_constraintTop_toTopOf="@id/linear_layout_1"
app:layout_constraintStart_toEndOf="@id/linear_layout_1"
app:layout_constraintTop_toBottomOf="@id/linear_layout_1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="foo"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bar"
android:thelayout_constraintHorizontal_weight="5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/linear_layout_2"
app:layout_constraintTop_toTopOf="@id/linear_layout_2"
app:layout_constraintBottom_toBottomOf="@id/linear_layout_2"
android:background="#a4c639"
/>
</android.support.constraint.ConstraintLayout>
我希望所有 3 个小部件各占 1/3 的空间。我怎样才能做到这一点?
【问题讨论】:
标签: android android-layout android-view android-constraintlayout