安卓报错:AS Error inflating class android.support.v7.widget.RecyclerView

build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28  //版本较高,用androidx开头的合适,之前在别的项目拷贝了一个android开头的依赖,哪里的sdk设置的版本都较低
    buildToolsVersion "29.0.2"//版本较高
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 19       // 应用程序支持api的下限
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //    RecyclerView 依赖库,(我出现这个问题是因为这个版本与上面sdk设置不兼容,现在的这个为兼容依赖)
    implementation 'androidx.recyclerview:recyclerview:1.0.0-alpha1'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

}

对应的xml文件xxx.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffececec">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    </RelativeLayout>
</LinearLayout>

此次情景
版本与上面sdk设置不兼容,一下几个参数对版本都做了限制

    minSdkVersion 19    //最小版本限制
    targetSdkVersion 28 //targetSdkVersion保证的是api的一致性。一般minSdkVersion <targetSdkVersion<= compileSdkVersion
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值