android中的CustomLoading(错误:drawable类型的预期资源)

时间:2015-04-17 15:31:02

标签: android

有人可以推荐在Android Project中使用CustomLoading的最佳方法。

我使用此post

我的代码:

_readNewsAsyncTaskManager = new ReadNewsAsyncTaskManager();

_loadigIcon.setImageResource(R.anim.loading_animation);// Error*
loadingViewAnim = (AnimationDrawable) _loadigIcon.getBackground();

// This line is to start Asyn Task only when OnCreate Method get completed, So Loading Icon Rotation Animation work properly
_loadigIcon.post(new Starter());

错误*:drawable类型的预期资源

loading_animation:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_loading_1" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_2" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_3" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_4" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_5" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_6" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_7" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_8" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_9" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_10" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_11" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_12" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_13" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_14" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_15" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_16" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_17" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_18" android:duration="50" />
    <item android:drawable="@drawable/ic_loading_19" android:duration="50" />
</animation-list>

2 个答案:

答案 0 :(得分:6)

这不是编译器错误。这只是编辑器验证错误(lint警告),因为这不是处理Drawable的常用方法。

有两种解决方案:

  1. 将loading_animation文件从anim文件夹移动到可绘制文件夹

  2. 替换
    _loadigIcon.setImageResource(R.anim.loading_animation);

    _loadigIcon.setImageResource(+R.anim.loading_animation);

  3. 参考答案:Android - Expected Resource of type ID

答案 1 :(得分:2)

我的解决方案:

忘掉这个post

将loading_animation文件从anim文件夹移动到可绘制文件夹

和loading_animation文件:

<animation-list
 xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
        <item android:duration="50">
            <clip
                android:clipOrientation="horizontal"
                android:drawable="@drawable/ic_loading_1"
                 />
        </item>
        <item android:duration="50">
            <clip
                android:clipOrientation="horizontal"
                android:drawable="@drawable/ic_loading_2"
                 />
        </item>
        <item android:duration="50">
            <clip
                android:clipOrientation="horizontal"
                android:drawable="@drawable/ic_loading_3"
                 />
        </item>
        <item android:duration="50">
            <clip
                android:clipOrientation="horizontal"
                android:drawable="@drawable/ic_loading_4"
                 />
        </item>
        <item android:duration="50">
            <clip
                android:clipOrientation="horizontal"
                android:drawable="@drawable/ic_loading_5"
                 />
        </item>
    </animation-list>

我用这个:

               <ProgressBar
                   android:layout_width="32sp"
                   android:layout_height="32sp"
                   android:layout_gravity="center_vertical|center_horizontal"
                   android:id="@+id/progressBar"
                   android:indeterminateDrawable="@drawable/loading_animation"/>