gpt4 book ai didi

安卓数据绑定(bind): visibility on include tag

转载 作者:IT王子 更新时间:2023-10-29 00:06:06 25 4
gpt4 key购买 nike

根据 http://developer.android.com/tools/data-binding/guide.html#imports ,我们可以在可见性上有这么简单的表达式:

<TextView
..
android:visibility="@{user.isAdult ? View.VISIBLE : View.GONE}"/>

但是当我尝试在 include 标记中执行相同操作时,如下所示:

<include
android:id="@+id/image_layout"
layout="@layout/image_layout"
android:visibility="@{notification.notifType == 0 ? View.VISIBLE : View.GONE}"/>

然后 Studio 不仅将表达式显示为红色,而且在构建它时,自动生成的绑定(bind)类中会出现以下错误:

Error:(138, 29) error: cannot find symbol method setVisibility(int)

这里是自动生成的绑定(bind)类发生错误的地方

// batch finished
if ((dirtyFlags & 0x3L) != 0) {
// api target 1
this.imageLayout.setVisibility(NotifTypeNotificatio1);
}
imageLayout.executePendingBindings();

最佳答案

我想你正在尝试做的事情看起来像这样:

在您包含的布局中,指定一个 bool 变量并将其绑定(bind)到所需 View 的可见性

<layout xmlns:android="http://schemas.android.com/apk/res/android">

<data>

<import type="android.view.View"/>

<variable
name="isVisible"
type="boolean"/>

</data>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="@{isVisible ? View.VISIBLE : View.GONE}"/>

</layout>

然后在你的调用布局中绑定(bind)你的值

<include
android:id="@+id/image_layout"
layout="@layout/image_layout"
bind:isVisible="@{notification.notifType == 0}"/>

关于安卓数据绑定(bind): visibility on include tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35723823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com