Error when adding CardView to layout

前端 未结 7 1267
借酒劲吻你
借酒劲吻你 2020-12-17 15:20

I wanted to try out the new toys that google gave us and I\'ve run into some trouble.

Here is my build.gradle:

apply plugin: \'com.android.applicatio         


        
相关标签:
7条回答
  • 2020-12-17 15:44

    try adding this line to your RelativeLayout

    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    
    0 讨论(0)
  • 2020-12-17 15:53

    I was able to get this to work by adding the following to my build.gradle: compile 'com.android.support:cardview-v7:21.+'

    Hope this helps.

    0 讨论(0)
  • 2020-12-17 15:54

    This is a bug in Android Studio, see https://code.google.com/p/android/issues/detail?id=79071

    One of the comments of the patch reads: "This was causing card view rendering to fail. CardView declared styles of the form CardView.Dark due to which the generated R class failed to load."

    Next version should have this fixed according to the bug report (the patch is on branch studio-1.0-dev). They say to build the project once as a workaround, but this does not fix it for me (even though I have exactly the same error and stack trace).

    0 讨论(0)
  • 2020-12-17 15:54

    Go to app, right click on: Open module -> Settings -> Dependencies.

    Go to "Declared dependencies" and you will find the "+" sign under the title.

    Click on "Library dependencies".

    Search for "Material" and go to "version section".

    Apply 1.0.0 and click "ok".

    And then search for card view you will get it on and the class

    0 讨论(0)
  • 2020-12-17 16:03

    It solved me by adding xmlns:card_view="http://schemas.android.com/apk/res-auto"

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                xmlns:card_view="http://schemas.android.com/apk/res-auto"> --->> ******
            ....
            ...
            <android.support.v7.widget.CardView>
        ..
    ...
    .....
    
            </android.support.v7.widget.CardView>
            </LinearLayout>
    
    0 讨论(0)
  • 2020-12-17 16:05

    I was able to get it to work on the emulator by changing my build.gradle to this:

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

    Make sure you have the support repository installed from the SDK Manager! Hope this helps

    EDIT: as someone suggested using 'com.android.support:cardview-v7:23.1' is a better practice but it not required.

    0 讨论(0)
提交回复
热议问题