Android 约束调整大小问题

Android 约束调整大小问题,android,android-constraintlayout,Android,Android Constraintlayout,我在ConstraintLayout中计算孩子的大小时遇到问题。我有3种看法: TextView(item\u quantity):我希望它无限增长,但不要将TextInputLayout从屏幕上推下 TextInputLayout(data\u entry\u layout):我希望它能够填充所有可用的水平空间,并且无论发生什么情况,其最小宽度都为120dp ImageView(camera\u scan):这不会增长,只需要不要被推离屏幕即可 如果item\u quantity有短文本,

我在
ConstraintLayout
中计算孩子的大小时遇到问题。我有3种看法:

  • TextView
    item\u quantity
    ):我希望它无限增长,但不要将
    TextInputLayout
    从屏幕上推下
  • TextInputLayout
    data\u entry\u layout
    ):我希望它能够填充所有可用的水平空间,并且无论发生什么情况,其最小宽度都为
    120dp
  • ImageView
    camera\u scan
    ):这不会增长,只需要不要被推离屏幕即可
如果
item\u quantity
有短文本,我希望它看起来像下图。我希望
数据\输入\布局
填满所有可用空间

如果
item\u quantity
有长文本,我希望它填充并增长,但我希望
data\u entry\u布局
永远不要小于
120dp
。我希望它尊重
minWidth
。所以,我希望它看起来像这样:

以下是我当前的配置:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    android:paddingTop="10dp"
    android:paddingBottom="10dp">

    <TextView
        android:id="@+id/item_quantity"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constrainedWidth="true"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@id/data_entry_layout"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintVertical_chainStyle="spread_inside"
        android:paddingStart="10dp"
        android:paddingEnd="10dp"
        android:text="90,000 Boxes of Stuff Are Needed"
        android:textColor="@color/color_on_background"
        android:textSize="@dimen/workflow_item_view_item_quantity_text_size" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/data_entry_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="@id/camera_scan"
        app:layout_constraintStart_toEndOf="@id/item_quantity"
        app:layout_constraintVertical_chainStyle="spread_inside"
        android:contentDescription="@string/disable_realwear_asr"
        android:paddingStart="10dp"
        android:paddingEnd="10dp"
        android:minWidth="120dp"
        app:errorIconDrawable="@null">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/data_entry"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/activity_instruction_data_entry_text_size"/>
    </com.google.android.material.textfield.TextInputLayout>

    <ImageView
        android:id="@+id/camera_scan"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginEnd="5dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="@id/data_entry_layout"
        app:layout_constraintTop_toTopOf="@id/data_entry_layout"
        android:background="@android:color/transparent"
        android:clickable="true"
        android:foreground="@drawable/ripple_selector"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:src="@drawable/qrcode_scan"
        android:visibility="visible"
        tools:ignore="ContentDescription,KeyboardInaccessibleWidget" />
</androidx.constraintlayout.widget.ConstraintLayout>

如果我将
item\u quantity
layout\u width
设置为
wrap\u content
,则用户界面可以使用短文本,但可以使用大文本将
数据条目\u layout
推离屏幕:


我一定错过了一些简单的东西。有什么方法可以让这两种情况都满足我的要求吗?

不要使用
android:minWidth
属性,尝试使用
app:layout\u constraintWidth\u min
。在调整元素大小时,ConstraintLayout似乎会忽略或否决带有“android”命名空间的某些属性。

不要使用
android:minWidth
属性,尝试使用
app:layout\u constraintWidth\u min
。在调整元素大小时,ConstraintLayout似乎会忽略或否决带有“android”命名空间的某些属性。

这很有效!我没有意识到
ConstraintLayout
有自己的最小宽度属性。非常感谢。这成功了!我没有意识到
ConstraintLayout
有自己的最小宽度属性。非常感谢。