Android DatabInding无效以三元条件设置尺寸

发布于 2025-02-11 05:19:04 字数 751 浏览 1 评论 0原文

我正在尝试使用来自视图模型的布尔值,以确定通过在三元操作中使用的维度来用于某些属性。问题是编译器说无法用float

我的代码设置属性:

android:layout_marginTop="@{landingManager.messageClickable ? @dimen/spacing_2 : @dimen/spacing_13}"

维度资源:

<dimen name="spacing_2">2dp</dimen>
<dimen name="spacing_13">13dp</dimen>

错误:

ERROR: Cannot find a setter for <android.widget.TextView android:layout_marginTop> that accepts parameter type 'float'

注意:我实际上可以ctrl+单击XML中的资源声明,该声明将将尺寸文件打开到这些行中。因此,我知道IDE正确地链接了这些

奇怪的是,它适用于我的文本属性属性,

android:textSize="@{landingManager.messageClickable ? @dimen/sp_18 : @dimen/sp_13}"

因此我完全迷失了为什么DP中的维度资源不起作用,而SP中的资源确实如此。

I'm trying to use a boolean from a View Model to determine which dimension to use for certain attributes by using it in a ternary operation. The problem is the compiler says the attribute cannot be set with a float

My Code:

android:layout_marginTop="@{landingManager.messageClickable ? @dimen/spacing_2 : @dimen/spacing_13}"

The Dimension Resources:

<dimen name="spacing_2">2dp</dimen>
<dimen name="spacing_13">13dp</dimen>

The Error:

ERROR: Cannot find a setter for <android.widget.TextView android:layout_marginTop> that accepts parameter type 'float'

Note: I can actually ctrl+click on the resource declarations in the XML that will open up the dimens file to those lines. So I know that the IDE is properly linking those

What is so weird is that this working for my textSize attribute

android:textSize="@{landingManager.messageClickable ? @dimen/sp_18 : @dimen/sp_13}"

So I am totally lost as to why a dimension resource in dp doesn't work, but a resource in sp does.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文