Android Data Binding: visibility on include tag
This is a bit late, but I have run across this recently.
I believe this is actually a bug in the Data Binding compiler as it is possible to set android:visibility
attribute on <include>
tag directly (ie. without Databinding).
You are able to pass all necessary parameters from parent xml into included xml via "http://schemas.android.com/apk/res-auto"
namespace.
The syntax is <res-auto_namespace>:<variable_name>
e.g. app:isVisible
For example
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/include_user_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:isVisible="@{true}" />
</android.support.design.widget.CoordinatorLayout>
</layout>
include_user_image.xml
<?xml version="1.0" encoding="utf-8"?>
<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>
Try:
this.imageLayout.getRoot().setVisibility(NotifTypeNotificatio1);
I imagine what you are trying to do would look something like this:
In the layout you are including, specify a boolean variable and bind it to the desired view's visibility
<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>
Then In your calling layout bind your value
<include
android:id="@+id/image_layout"
layout="@layout/image_layout"
bind:isVisible="@{notification.notifType == 0}"/>