本文介绍了视图绑定错误:与属性android:visibility不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用数据绑定设置visibility
和ImageView
的src
.我不知道为什么会出现此错误,而且我确实相信这在某一时刻起作用,但是我可能是错的.
I'm trying to set the visibility
and the src
of an ImageView
using data binding. I don't know why this error is showing up, and I truely believe that this was working at one point, but I could be wrong.
布局:
<data>
<import type="android.view.View" />
<import type="android.support.v4.content.ContextCompat" />
<variable
name="viewData"
type="com.myapp.SomethingViewData" />
</data>
...
<ImageView
...
android:src="@{ContextCompat.getDrawable(context, viewData.getIconResource())}"
android:visibility="@{viewData.getIconVisibility() ? View.VISIBLE : View.GONE}" />
数据类
@Parcelize
data class SomethingViewData(val iconResource: Int,
val iconVisibility: Boolean) : Parcelable
错误消息:
error: '@{ContextCompat.getDrawable(context, viewData.getIconResource())}' is incompatible with attribute android:src (attr) reference|color.
error: '@{viewData.getIconVisibility() ? View.VISIBLE : View.GONE}' is incompatible with attribute android:visibility (attr) enum [gone=2, invisible=1, visible=0].
这是什么意思,我该如何解决?
What does this mean and how do I fix it?
推荐答案
哇,所以dataBinding { enabled = true }
从我的应用程序模块build.gradle文件中删除了.加回去,一切都像以前一样工作.
Wow, so, somehow dataBinding { enabled = true }
was removed from my app modules build.gradle file. Adding it back and everything worked like before.
这篇关于视图绑定错误:与属性android:visibility不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!