附录:
我意识到问题与:
app:visibleGone="@{isLoaded}"
采用以下布局:
<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>
<variable
name="isLoaded"
type="boolean" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:visibleGone="@{isLoaded}" />
</android.support.v4.widget.SwipeRefreshLayout>
<include
layout="@layout/network_state_item"
app:visibleGone="@{!isLoaded}" />
</FrameLayout>
</layout>
我在Bitbucket中有以下分支:https://bitbucket.org/ali-rezaei/tmdb/src/dataBinding/
构建项目时出现以下Kotlin compiler
错误:
e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
如果您能帮助我,我表示感谢。
这是我的项目build.gradle:
buildscript {
ext.kotlin_version = '1.2.60'
ext.gradle_version = '3.1.4'
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$gradle_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
这是我的应用程序build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
androidExtensions {
experimental = true
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.sample.android.tmdb"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
dataBinding {
enabled = true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Support libraries
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
implementation "com.android.support:design:$rootProject.supportLibraryVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
// Architecture components
implementation "android.arch.paging:runtime:$rootProject.paging"
implementation "android.arch.lifecycle:runtime:$rootProject.lifecycle"
implementation "android.arch.lifecycle:extensions:$rootProject.lifecycle"
//DataBinding
kapt "com.android.databinding:compiler:$gradle_version"
//Gson
implementation 'com.google.code.gson:gson:2.8.2'
//Retrofit
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
//Dagger
implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
kapt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
compileOnly 'org.glassfish:javax.annotation:10.0-b28'
implementation "com.google.dagger:dagger-android:$rootProject.daggerVersion"
implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
// Network
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"
kapt "com.github.bumptech.glide:compiler:$rootProject.glideVersion"
//Butter knife
implementation "com.jakewharton:butterknife:$rootProject.butterknifeVersion"
kapt "com.jakewharton:butterknife-compiler:$rootProject.butterknifeVersion"
//Timber
implementation 'com.jakewharton.timber:timber:4.5.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
作为示例,您可以查看:https://www.moveoapps.com/blog/how-to-use-data-binding-library-with-kotlin-a-step-by-step-guide/
答案 0 :(得分:0)
将通过在项目中将以下方法创建为Kotlin文件来解决问题:
@BindingAdapter("visibleGone")
fun View.visibleGone(visible: Boolean) {
visibility = if (visible) View.VISIBLE else View.GONE
}