android - SDK 5.0 RecyclerView 无法实例化

标签 android android-layout android-fragments android-5.0-lollipop

我正在测试新的 API 21,我尝试创建一个 RecyclerView,但我遇到了依赖性问题。

错误看起来像这样

enter image description here

我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin">
    <!-- A RecyclerView with some commonly used attributes -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/mRecyclerView"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

还有我的gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.agonist.samplify"
        minSdkVersion 17
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:+'
    compile 'com.android.support:recyclerview-v7:+'
}

我不知道该怎么办。我试图清理/构建项目,但它留在这里。有什么想法吗?

编辑:最终这只是一个 IDE 预览问题。在执行期间一切正常

最佳答案

新的 RecyclerView 尚不能在 Studio 中使用。谷歌正在努力修复。 ( Open Issue 72117 )

关于android - SDK 5.0 RecyclerView 无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26452657/

相关文章:

android - Flutter中的无边框选择高亮效果

java - 从 Activity 中将文本设置为 Fragment

android - 如何将tablayout的指示器从底部更改为顶部?

android - SimpleDateFormat 解析器

java.net.UnknownHostException : Unable to resolve host "api. themoviedb.org

android - ionic : Adding platform gives error

java - 如何以编程方式获取颜色属性的值

android - TextView 不显示。但是在 logcat 中显示时一切正常

android - 在android中以xml格式在服务器上传递请求

android - 如何使用 fragment 在 TabLayout 中的每个选项卡中显示不同的布局