相关疑难解决方法(0)

将所有子宽度与 ConstraintLayout 中的最宽子宽度匹配,宽度 = 包装内容

ConstraintLayout 功能强大,但有时也很棘手。

我想实现一个布局ConstraintLayout,可以通过LinearLayout.

  • 蓝色区域是父约束布局。红色部分是LinearLayout。我想通过保持以下条件将此 LinearLayout 转换为 ConstraintLayout

    1. 所有子项(按钮)的宽度应与最宽的子项匹配。
    2. 最宽的孩子不是固定的。它将在运行时更改。
    3. 红框应该保持不变wrap_content

我曾尝试使用障碍、指南和约束布局的其他属性,但没有成功。

这是代码LinearLayout

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#476dce"
android:padding="16dp">

  <LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:background="#f5aaaa">


    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:text="Small" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:text="Bigggggeer" />


    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:text="Even Bigggggggggeer" />

  </LinearLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-constraintlayout

7
推荐指数
1
解决办法
977
查看次数

约束布局 - 宽度最大的两个视图

我想创建一个布局(使用约束布局),如下所示:

在此处输入图片说明

在不同的语言中,Button1 可能比 button2 大。我怎样才能做到这一点?

我只能在包含两个按钮的约束中使用 LinearLayout 来实现这一点,但我试图只使用一个布局。

谢谢

android android-layout android-constraintlayout

4
推荐指数
2
解决办法
1581
查看次数