android - "The following classes could not be found"在布局中使用自定义 Kotlin View

标签 android android-studio kotlin android-custom-view

我遇到了在 XML 布局文件中包含自定义 Kotlin View 的问题。这是代码:

class CustomView: RelativeLayout {

    /**
     * Programmatic constructor
     */
    constructor(aVariable: Boolean, context: Context): super(context) { ... }

    /**
     * XML constructor
     */
    @JvmOverloads
    constructor(context: Context, attributeSet: AttributeSet? = null, defStyle: Int = 0): super(context, attributeSet, defStyle) { ... }

}

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.turingtechnologies.materialscrollbar.CustomView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

然后布局预览器提示:

“缺课-

找不到以下类: com.turingtechnologies.materialscrollbar.CustomView(修复构建路径、编辑 XML、创建类)”

注意:这是 AS 3.0 beta 3

最佳答案

确认错误 https://issuetracker.google.com/issues/62255811 .修复应该会出现在下一版本的 Android Studio 中。

关于android - "The following classes could not be found"在布局中使用自定义 Kotlin View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45909039/

相关文章:

android - 在 Android 中将多个纹理映射到立方体的面

java - Android SQLite : get number of rows in a table?

android - 更新 android studio 3.1 后运行应用程序时出现错误

android - 空 queryProductDetailsAsync 问题

android - 未以编程方式获得 SOAP Web 服务的正确响应

java - Android 4 : Failed resolving class from org. simalliance.openmobileapi 包

android - 任何人都可以检查我的 manifest.xml 吗?

android - 尝试构建未签名的APK不断收到错误任务 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败

android - 找不到选项来禁用离线gradle

android - Jetpack Compose WebView 处理返回导航并转到上一页