小编Xsi*_*ims的帖子

Jetpack Compose 预览中的 ViewDataBinding XML 文件

我无法在 Jetpack Compose 版本 1.0.5 中预览带有数据的 ViewDataBinding

我设法使用:

  1. 没有<layout>标签的Xml 文件感谢:/sf/answers/4691181141/

片段.kt

@Preview
@Composable
fun PreviewExample() {
    AndroidViewBinding(MyViewBinding::inflate)
}
Run Code Online (Sandbox Code Playgroud)

my_view.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

    <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
  1. 带有<layout>标签但没有<data>标签的 Xml 文件,感谢:/sf/answers/4595762811/

片段.kt

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

    <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

my_view_with_layout_tags.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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/text_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout> …
Run Code Online (Sandbox Code Playgroud)

xml android android-databinding android-jetpack-compose

12
推荐指数
0
解决办法
2014
查看次数

Android Lint:Kotlin Dispatchers 未解析参考,但编译工作正常

我已经尝试过使缓存无效清理构建和重建项目也已完成。但我仍然不断收到以下未解决的参考:Dispatchers、launch、withContext、delay...但是 CoroutineScope没有标记为未解决的参考,即import kotlinx.coroutines。* 未标记为未知,并且该项目正在编译(它已经工作了几个月,它不是最近的项目)。

安卓工作室:4.0.1

设置 > 语言和框架 > Kotlin :当前kotlin 插件版本:1.4.10-release-Studio4.0-1

构建.gradle

buildscript {
    ext {
        // KOTLIN
        kotlin_coroutines_version = '1.3.5'
        kotlin_version = '1.3.71'
       ...
    }

 dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
Run Code Online (Sandbox Code Playgroud)

模块构建.gradle

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 29

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 29
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release { …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-lint android-studio kotlin-coroutines

5
推荐指数
1
解决办法
1864
查看次数