Android DatabInding无效以三元条件设置尺寸
我正在尝试使用来自视图模型的布尔值,以确定通过在三元操作中使用的维度来用于某些属性。问题是编译器说无法用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论