Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/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约束尺寸比率的浮点无效_Android_Layout_Android Constraintlayout - Fatal编程技术网

Android 布局\u约束尺寸比率的浮点无效

Android 布局\u约束尺寸比率的浮点无效,android,layout,android-constraintlayout,Android,Layout,Android Constraintlayout,我一直在学习如何在“活动”窗口中约束图像,当我尝试应用1:1的纵横比时,图像将从活动上的原始预期位置移动,并作为0dp x 0dp ImageView向上移动到“活动”的左角 我的代码说这是无效浮点的错误: 这对我来说很神秘,因为系统还告诉我,比率可以列为浮动或比率。有人告诉我我没有疯,当我还是个孩子的时候,他们被一个冒号隔开 我多次删除ImageView,并以相同的比例多次重新添加约束。不过,Android Studio不知道1:1的比例是多少。约束条件如下所示: Top Constraint

我一直在学习如何在“活动”窗口中约束图像,当我尝试应用1:1的纵横比时,图像将从活动上的原始预期位置移动,并作为0dp x 0dp ImageView向上移动到“活动”的左角

我的代码说这是无效浮点的错误:

这对我来说很神秘,因为系统还告诉我,比率可以列为浮动或比率。有人告诉我我没有疯,当我还是个孩子的时候,他们被一个冒号隔开

我多次删除ImageView,并以相同的比例多次重新添加约束。不过,Android Studio不知道1:1的比例是多少。约束条件如下所示:

Top Constraint
+ ImageView1
+ ImageView2
Bottom constraint
app:layout_constraintDimensionRatio="1:1"
Invalid Float

ImageView以0dp x 0dp图像的形式出现在我的活动窗口的顶部。

我不确定这是否正是您想要的,或者是否有任何帮助,但以下是我如何成功地将其用于我的应用程序。我相信您遇到的问题可能是您正在使用的ImageView缺少约束,这就是为什么它可能会出现在屏幕的左上角。但是,我不能自信地说,因为我看不到您的代码。我可能错了,因为我不是专业人士,但这是我目前最好的猜测

<ImageView
            android:id="@+id/userPicture"
            android:src="@drawable/user_picture"
            android:contentDescription="Update later"

            android:layout_width="125dp"
            android:layout_height="wrap_content"

            android:layout_marginStart="0dp"
            android:layout_marginEnd="0dp"
            android:layout_marginTop="40dp"
            android:layout_marginBottom="15dp"

            android:scaleType="centerCrop"
            android:adjustViewBounds="true"

            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/currentTrackPlayingText"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"

            app:layout_constraintDimensionRatio="1:1" />
这将产生以下内容,这些内容仅限于屏幕上的其他方面抱歉,我没有足够的代表在此处显示图像


这个问题是完全正确的,我在其他任何地方都找不到答案。 问题是,如果您知道什么是比率,并仔细阅读错误,您会注意到,出于某种原因,布局希望您对其使用浮点表示法

例如,如果希望比率为2:1,则希望宽度为高度的两倍。因此,您可以提供这样的宽度/高度比例,因为您希望它是1乘1,只需将app:layout\u constraintDimensionRatio=1,并感到高兴


tl;dr:ratio 1:1=1/1=1->app:layou\u constraintDimensionRatio=1

似乎约束布局的实现发生了变化

附录:布局约束尺寸比=W,661:165

这已经不起作用了。我得到消息无效浮动

解决办法很简单。此参数现在需要一个浮点值。在上面的例子中,我们所要做的就是除以665/165=4.006,我们可以将值四舍五入为4

因此,这条线现在可以按预期工作:

应用:布局约束尺寸比=4


希望这个答案有帮助。

你没有疯。但是你需要提供更多的信息。用您正在使用的xml代码更新问题。欢迎来到StackOverflow
<ImageView
            android:id="@+id/userPicture"
            android:src="@drawable/user_picture"
            android:contentDescription="Update later"

            android:layout_width="125dp"
            android:layout_height="wrap_content"

            android:layout_marginStart="0dp"
            android:layout_marginEnd="0dp"
            android:layout_marginTop="40dp"
            android:layout_marginBottom="15dp"

            android:scaleType="centerCrop"
            android:adjustViewBounds="true"

            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/currentTrackPlayingText"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"

            app:layout_constraintDimensionRatio="1:1" />