Recyclerview preview showing grey screen with android.support.v7.widget.RecyclerView in center

两盒软妹~` 提交于 2019-12-08 13:07:29

问题


I am trying to add Recyclerview to my activity layout but the layout preview shows me this. I went through all possible answers which i could find out and tried doing things like

  1. changing app theme to holo.light
  2. adding <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> to res>styles.xml
  3. went through all possible relating questions like this and this as well and made changes accordingly in my code.

My build.gradle file is as follows:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.1'
    defaultConfig {
        applicationId "com.myapp.test"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:28.0.0-alpha3'
    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'
    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
    implementation 'com.android.volley:volley:1.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'

}

The same problem occurs when i am trying to use coordinate layout as well in my activity. I am using android studio 3.1.3 and my device that m targeting is of oreo version.

I am not able to figure out whats the problem. Kindly help me out.


回答1:


Try this:

compileSdkVersion 27
buildToolsVersion '27.0.1'
targetSdkVersion 27

Hope this will help.




回答2:


Try with this com.android.support:recyclerview-v7:20.0.+
or remove alpha and try it




回答3:


I think you should try changing your sdk version and using an older version of recyclerview (probably version 27) and other libraries you used to see if it works.




回答4:


Try doing 'Invalidate Cache / Restart' in 'File' in Android Studio.

If this doesn't work then try the following:

Add this to your build.gradle (project) file :

configurations.all {
    resolutionStrategy {
        force 'com.android.support:recyclerview-v7:28.0.0-alpha3'
    }
}


来源:https://stackoverflow.com/questions/51723986/recyclerview-preview-showing-grey-screen-with-android-support-v7-widget-recycler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!