如何通过数据绑定为自定义视图填充线性布局

问题描述 投票:0回答:1

我只想用一些Vertical LinearLayout制作一个地图,在每个地图中都有一个Horizo​​ntal LinearLayout,并且在每个布局中都希望为一个类似于以下代码的视图充气:

each_cell.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>

我将将此[[Horizo​​ntal LL视图添加到我的主Vertical LL并将创建地图]

和科特琳代码:

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.

android kotlin data-binding android-databinding
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.