数据绑定不适用于组件“底表”

时间:2019-12-18 17:44:38

标签: android-databinding android-studio-3.0 bottom-sheet

Android Studio 3.6

在app / build.gradle中:

android {
    dataBinding {
        enabled = true
    }
    // Configure only for each module that uses Java 8
    // language features (either in its source code or
    // through dependencies). E.g. lambda expressions.
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
    compileSdkVersion 29

在我的bottom_sheet.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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bottom_sheet_top_bg"
    android:orientation="horizontal"
    android:padding="16dp"
    app:behavior_hideable="false"
    app:behavior_peekHeight="90dp"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:orientation="vertical">

,这里是main_layout.xml:

<data>

    <import type="java.util.Date" />

  <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/mainContaerButotnSheet"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">

            <androidx.coordinatorlayout.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="180dp"
                app:layout_constraintTop_toTopOf="parent">

                <include layout="@layout/bottom_sheet" />

            </androidx.coordinatorlayout.widget.CoordinatorLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

这里是我的MainActivity:

 import com.myproject.client.databinding.MainActivityBinding
    import java.util.*
    import com.synnapps.carouselview.ImageListener
    import android.widget.ImageView
    import android.widget.LinearLayout
    import androidx.databinding.ObservableDouble
    import com.google.android.material.bottomsheet.BottomSheetBehavior

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        dataBinding =
            DataBindingUtil.setContentView(this, R.layout.main_activity)
        dataBinding.setHandler(this)

        val profile = createStubProfile()
        dataBinding.setVariable(BR.item, profile)
        dataBinding.executePendingBindings(); //bind

        init()
    }

很好,工作正常。底页成功显示。 但我想在bottom_sheet.xml

中使用数据出价

我在bottom_sheet.xml中使用它

<?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"
    xmlns:tools="http://schemas.android.com/tools">

    <data></data>

    <LinearLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bottom_sheet_top_bg"
        android:orientation="horizontal"
        android:padding="16dp"
        app:behavior_hideable="false"
        app:behavior_peekHeight="90dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

现在我得到了错误:

0 个答案:

没有答案