【发布时间】:2020-05-30 10:53:37
【问题描述】:
我只想制作一个带有一些 Vertical LinearLayout 的地图,其中每个都有一个 Horizontal LinearLayout 并且在每个布局中都想膨胀一个类似于下面的代码:
每个单元格.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="live" type="Integer" />
<variable name="i" type="Integer" />
<variable name="j" type="Integer" />
</data>
<ImageView
android:id="@+id/itemView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
app:setI="@{i}"
app:setJ="@{j}"/>
each_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/row_instance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:orientation="horizontal">
</LinearLayout>
我将把这个 Horizontal LL 视图添加到我的主 Vertical LL 并创建地图
和 kotlin 代码:
val cell = DataBindingUtil.inflate<EachCellBinding>(inflater , R.layout.each_cell , HorizontalLinearLayout.row_instance , true )
但错误是:
Required DataBindingComponent is null in class EachCellBindingImpl. A BindingAdapter in com.example.gameoflife.SartFragment.StartFragment is not static and requires an object to use, retrieved from the DataBindingComponent. If you don't use an inflation method taking a DataBindingComponent, use DataBindingUtil.setDefaultComponent or make all BindingAdapter methods static.
【问题讨论】:
-
您在哪里声明了方法 app:setI 和 app:setJ 的绑定适配器?
标签: android kotlin data-binding android-databinding