1

在我之前的应用程序中,我添加了卡片视图和材料选项卡。该应用程序在 SDK 17-21 的所有兼容设备上运行,但在添加支持设计库后,该应用程序在低于 21 的 SDK 上崩溃。

我的依赖是:

compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:23.0.0'
compile 'com.quinny898.library.persistentsearch:library:1.0.0-SNAPSHOT'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.github.mrengineer13:snackbar:1.2.0'
compile 'com.github.d-max:spots-dialog:0.4@aar'
compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
compile 'com.github.clans:fab:1.6.1'
compile 'io.karim:materialtabs:2.0.2'
compile 'com.wrapp.floatlabelededittext:library:0.0.6'
compile 'com.orhanobut:dialogplus:1.10@aar'
compile 'com.github.lawloretienne:imagegallery:0.0.8'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.bowyer.app:fabtransitionlayout:0.2.0@aar'
compile 'me.tatarka.support:jobscheduler:0.1.1'

cardView的一部分

 <android.support.v7.widget.CardView
        android:id="@+id/card_view1"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="10dp"
        card_view:cardCornerRadius="4dp"
        card_view:cardElevation="4dp"
        >

LogCat 显示:

    11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime: FATAL EXCEPTION: main
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime: Process: com.example.razon30.totalmovie, PID: 32692
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime: java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.CardViewEclairMr1.getShadowBackground(CardViewEclairMr1.java:159)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.CardViewEclairMr1.getMinWidth(CardViewEclairMr1.java:150)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.CardView.onMeasure(CardView.java:181)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.measure(View.java:16834)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5374)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.measure(View.java:16834)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$LayoutManager.measureChildWithMargins(RecyclerView.java:6934)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1397)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1334)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:563)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2847)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3145)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1627)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.View.layout(View.java:15125)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4862)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2347)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2053)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1216)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6255)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.view.Choreographer.doCallbacks(Choreographer.java:591)
11-05 14:44:23.276 32692-32692/com.example.razon30.totalmovie E/AndroidRuntime:     at android.vie

怎么了?

4

2 回答 2

0

在 api 级别 21 及之后表示的卡片视图,因此它不会在 api 级别低于 21 的设备中运行也就不足为奇了。

于 2015-11-15T17:38:52.317 回答
0

试试这个吧

 cardView.setCardBackgroundColor(Color.WHITE);
于 2015-11-05T14:39:52.663 回答