扩大微调器布局时收到错误

时间:2019-03-05 18:34:14

标签: android

因此,我正在尝试为微调框下拉菜单设置自定义图片。我已经解决了一些stackoverflow问题,它们似乎都具有相同的解决方案来完成任务。出于某些原因,尝试时会出现此错误java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.plansly/com.example.plansly.planner}: android.view.InflateException: Binary XML file line #36: Binary XML file line #36: Error inflating class Spinner at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6944) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) Caused by: android.view.InflateException: Binary XML file line #36: Binary XML file line #36: Error inflating class Spinner Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class Spinner Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.plansly:drawable/ic_spinner_dropdown with resource ID #0x7f07006d Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_spinner_dropdown.xml from drawable resource ID #0x7f07006d at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:837) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:659) at android.content.res.Resources.loadDrawable(Resources.java:900) at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953) at android.content.res.TypedArray.getDrawable(TypedArray.java:928) at android.view.View.<init>(View.java:5078) at android.view.ViewGroup.<init>(ViewGroup.java:597) at android.widget.AdapterView.<init>(AdapterView.java:280) at android.widget.AbsSpinner.<init>(AbsSpinner.java:74) at android.widget.Spinner.<init>(Spinner.java:258) at android.widget.Spinner.<init>(Spinner.java:225) at android.widget.Spinner.<init>(Spinner.java:175) at android.support.v7.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:196) at android.support.v7.widget.AppCompatSpinner.<init>

活动微调器位于:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/activityBackGroundColor"
    tools:context=".planner">
<Spinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="467dp"
        android:paddingStart="0dp"
        android:spinnerMode="dropdown"
        android:layout_marginRight="30dp"
        android:background="@drawable/ic_spinner_dropdown"
        >
    </Spinner>
</RelativeLayout>

ic_spinner_dropdown可绘制文件:

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <corners android:radius="2.5dp" />
        </shape>
    </item>
    <item android:right="64dp">
        <bitmap
            android:gravity="right|center_vertical"
            android:src="@drawable/more_vert" />
    </item>
</layer-list>

1 个答案:

答案 0 :(得分:0)

我更改了ic_spinner_dropdown可绘制对象,从而解决了该问题。 来自:

`

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <corners android:radius="2.5dp" />
        </shape>
    </item>
    <item android:right="64dp">
        <bitmap
            android:gravity="right|center_vertical"
            android:src="@drawable/more_vert" />
    </item>
</layer-list>

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:right="64dp"
        android:drawable="@drawable/more_vert"
        android:gravity="left|center_vertical">
    </item>
</layer-list>

换句话说,删除位图代码,并在item标签中设置可绘制源,并使用重力设置下拉图像的位置