Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 布局“U constraintWidth”U default=";“包装”;是否有其他选择?_Android_Android Constraintlayout - Fatal编程技术网

Android 布局“U constraintWidth”U default=";“包装”;是否有其他选择?

Android 布局“U constraintWidth”U default=";“包装”;是否有其他选择?,android,android-constraintlayout,Android,Android Constraintlayout,我在textview中使用了这个布局\u constraintWidth\u default=“wrap”来包装textview内容(右边是imageview),因为textview中的文本增加了textview区域将增大,从而将imageview向右移动 layout_constraintWidth_default="wrap" 由于它已被弃用,有其他选择吗 Logcat 正如Android开发者的文档中所述: 在1.1之前的版本中,它们将被视为文字维度——这意味着,约束不会限制结果维度。虽

我在textview中使用了这个布局\u constraintWidth\u default=“wrap”来包装textview内容(右边是imageview),因为textview中的文本增加了textview区域将增大,从而将imageview向右移动

layout_constraintWidth_default="wrap"
由于它已被弃用,有其他选择吗

Logcat


正如Android开发者的文档中所述:

在1.1之前的版本中,它们将被视为文字维度——这意味着,约束不会限制结果维度。虽然一般来说,这已经足够(而且更快),但在某些情况下,您可能希望使用WRAP_内容,同时继续强制约束以限制生成的维度。在这种情况下,可以添加一个相应的属性:

app:layout_constrainedWidth=“true | false”


因此,使用
layout\u constrainedWidth=“true”
而不是
layout\u constrainedWidth\u default=“wrap”

如果维度设置为
wrap\u CONTENT
,则在1.1
之前的版本中,它们将被视为文字维度,这意味着约束不会限制生成的维度

通常要求视图的宽度或高度保持包裹状态 内容而不是匹配约束或匹配父项,但不幸的是 包裹内容覆盖应用的约束,并与 宽度或高度更改时的约束。对于版本1.1.0,此问题 通过使用

FYI

您可以使用
百分比
表示宽度和高度。尺寸应为
匹配约束(0dp)
,并且
应用程序:布局约束宽度默认值=“百分比”
应用程序:布局约束宽度默认值=“百分比”
需要设置为百分比

示例

<TextView
    android:id="@+id/txtView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Hello Width In Percentage"
    app:layout_constraintWidth_default="percent"
    app:layout_constraintWidth_percent="0.5"
    app:layout_constraintLeft_toLeftOf="parent" />

以下是我对解决方案所做的更改,imageview将不会超出可见屏幕区域:

android:layout_width="wrap_content"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintHorizontal_chainStyle="packed"

您可以尝试以下方法:

android:layout_width="wrap_content"
app:layout_constrainedWidth="true"

宽度不能为“0dp”

layout\u constraintWidth\u default=“wrap”
已弃用。确定?@IntelliJAmiya是在logcatInclude logcat中获取此错误消息question@IntelliJAmiya阿多克。然后用他们在Logcatt上的建议谢谢,这正是我想要的。我在寻找一天中最好的部分,但在其他任何地方都找不到这个解决方案。
android:layout_width="wrap_content"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintHorizontal_chainStyle="packed"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text asdasdasdasdasdasdasdasdasdadsasdasdasdasdasdasdasd"
            app:layout_constrainedWidth="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/image"
            app:layout_constraintHorizontal_bias="0"
            app:layout_constraintHorizontal_chainStyle="packed"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/text"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
android:layout_width="wrap_content"
app:layout_constrainedWidth="true"