【问题标题】:ConstraintLayout not wrapping multiline EditTextConstraintLayout 不包装多行 EditText
【发布时间】:2018-06-23 02:24:00
【问题描述】:

我的ConstraintLayout(位于CardView 内)没有正确包装内容的高度。内容包括一个EditText,它是一行,但在用户编写文本时会扩展为多行。 ConstraintLayout 在屏幕上的大小就像多行(在这种情况下最多 3 行)已经存在一样。基于this documentation,似乎设置constrainedHeight=true 可以解决问题,但我不知道在xml 中的何处或如何执行此操作。

有人知道如何使ConstraintLayout 的高度缩小到编辑文本的正确大小吗?

<android.support.constraint.ConstraintLayout
        android:id="@+id/constraintLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" >

        <EditText
            android:id="@+id/etMessage"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:inputType="text|textCapSentences|textMultiLine"
            android:lines="3"
            android:maxLength="200"
            android:maxLines="5"
            android:minLines="1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 发布您的完整布局,因为似乎其他视图正在影响它。还有为什么只有一个view就用约束布局,可以直接把edittext放到卡片里面,不用把它包裹在约束布局里

标签: android android-edittext multiline android-constraintlayout


【解决方案1】:

尝试在editext上使用maxHeight,为我解决了问题。

【讨论】:

    猜你喜欢
    • 2020-10-04
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 2010-10-10
    • 2013-08-09
    • 1970-01-01
    • 2013-01-12
    • 2016-03-29
    相关资源
    最近更新 更多