小编Mar*_*nas的帖子

是否可以根据类方法响应有条件地显示 XML 包含?

我想知道是否可以使用 DataBinding 根据方法布尔响应有条件地显示布局。这就是我想要做的

XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <variable
            name="View"
            type="android.view.View"/>

        <variable
            name="App"
            type="com.app.JTApp"/>
    </data>

    <include layout="@layout/view_checkout_total_cardview"
             android:visibility="@{App.isLandscape() ? View.GONE : View.VISIBLE}" />

</layout>
Run Code Online (Sandbox Code Playgroud)

JTApp 类:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <variable
            name="View"
            type="android.view.View"/>

        <variable
            name="App"
            type="com.app.JTApp"/>
    </data>

    <include layout="@layout/view_checkout_total_cardview"
             android:visibility="@{App.isLandscape() ? View.GONE : View.VISIBLE}" />

</layout>
Run Code Online (Sandbox Code Playgroud)

目前这不起作用。我错过了什么或者这是不可能的吗?我来自网络,使用 Angular 等框架可以做到这一点。

xml android android-databinding

3
推荐指数
1
解决办法
2737
查看次数

标签 统计

android ×1

android-databinding ×1

xml ×1