错误膨胀类Spinner

时间:2018-08-01 07:01:51

标签: android android-layout android-spinner

我想自定义 Spinner 。我这样制作了 background_spinner.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item>
                <shape>
                    <solid android:color="@android:color/white" />
                    <corners android:radius="4dp" />
                    <padding android:left="8dp" />
                </shape>
            </item>
            <item>
                <bitmap android:gravity="left"     android:src="@drawable/ic_arrow_drop_down_grey_24dp" />
            </item>
        </layer-list>
    </item>
</selector>

我将此代码添加到了我的 styles.xml

<style name="spinner_style">
    <item name="android:background">@drawable/background_spinner</item>
</style>

这是我的纺车

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@drawable/spinner_background">

    <Spinner
        android:id="@+id/favourites_spinner"
        style="@style/spinner_style"
        android:layout_width="match_parent"
        android:layoutDirection="rtl"
        android:gravity="left"
        android:layout_height="wrap_content" />
</RelativeLayout>

ic_arrow_drop_down_grey_24dp 是:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#C4C4C4"
        android:pathData="M7,10l5,5 5,-5z"/>
</vector>

在SDK = 19的设备中可以,但是在SDK = 22的另一设备中,会发生此错误:

  

android.view.InflateException:二进制XML文件第31行:错误放大了类Spinner

我的错误日志是:

08-01 11:37:52.409 4558-4558/com.myapp.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.myapp.app, PID: 4558
    android.view.InflateException: Binary XML file line #31: Error inflating class Spinner
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:767)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:508)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
        at com.myapp.app.MyFragment.onCreateView(FavouritesFragment.java:56)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2346)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1428)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
        at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2215)
        at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:649)
        at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:167)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1238)
        at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1616)
        at android.view.View.measure(View.java:17577)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5538)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
        at android.view.View.measure(View.java:17577)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1632)
        at android.view.View.measure(View.java:17577)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5538)
        at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:739)
        at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:811)
        at android.view.View.measure(View.java:17577)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5538)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
        at android.view.View.measure(View.java:17577)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5538)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
        at android.view.View.measure(View.java:17577)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5538)
        at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:739)
        at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:811)
        at android.view.View.measure(View.java:17577)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5538)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
        at android.view.View.measure(View.java:17577)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5538)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
        at android.widget.LinearLayout.

0 个答案:

没有答案