对于layout_constraintDimensionRatio无效的Float [英] Invalid Float for layout_constraintDimensionRatio

查看:145
本文介绍了对于layout_constraintDimensionRatio无效的Float的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在上一堂关于如何在活动窗口中约束图像的课程,当我尝试将宽高比设为1:1时,图像会从其在活动中的原始预期位置移开,并向上移动到活动的左上角为0dx x 0dp ImageView.

I've been following a lesson on how to constrain images within an activity window and, when I try to apply an aspect ratio of 1:1, the image moves away from it's original intended location on the activity and up into the left hand corner of the activity as a 0dp x 0dp ImageView.

我的代码说这是"Invalid Float" 的错误:

My code is saying this is an error of "Invalid Float":

app:layout_constraintDimensionRatio="1:1"

这对我来说很神秘,因为系统还告诉我该比率可以列为FLOAT或RATIO.有人告诉我,我并不疯狂,当我从小学习比率时,它们就被冒号隔开了.

This is mysterious to me because the system ALSO tells me that the ratio can be listed as either a FLOAT or a RATIO. Someone tell me I'm not crazy and when I learned ratios as a kid they were separated by a colon.

我已多次删除ImageViews并重新添加了相同的RATIO数量约束.尽管如此,Android Studio仍不知道1:1的比例是多少.约束如下:

I've removed the ImageViews multiple times and re-added constraints an equal RATIO amount of times. Still, Android Studio doesn't know what a 1:1 ratio is. The constraint goes as follows:

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

ImageView作为0dp x 0dp图像位于我的活动窗口的顶部.

The ImageView is at the top of my activity window as a 0dp x 0dp image.

推荐答案

约束布局的实现似乎有所变化.

It seems that there was a change in the constraint layout implementation.

app:layout_constraintDimensionRatio ="W,661:165"

app:layout_constraintDimensionRatio="W,661:165"

这不再起作用.我收到消息无效的浮动"

This does not work any longer. I get the message "Invalid float"

解决方案很简单.现在,此参数需要一个浮点值.在上面的示例中,我们要做的就是除以665/165 = 4.006(我们可以将值舍入为4)

The solution is simple. This parameter now requires a float value. In the above example, all we have to do is to divide 665/165 = 4.006 (We can round the value to 4)

因此此行现在可以按预期工作:

So this line now works as expected:

app:layout_constraintDimensionRatio ="4"

app:layout_constraintDimensionRatio="4"

希望这个答案有帮助.

这篇关于对于layout_constraintDimensionRatio无效的Float的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆