简体   繁体   中英

CustomLoading in android ( error : expected resource of type drawable )

Can somebody recommend the best way to CustomLoading in android Project.

i using this post .

my code :

_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());

Error* : expected resource of type 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>

This is not a compiler error. It is just editor validation error(lint warning) as this is not a common way to deal with Drawable.

There has 2 solutions:

  1. Move the loading_animation file from anim folder to drawable folder

  2. Replace
    _loadigIcon.setImageResource(R.anim.loading_animation);
    with

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

Reference the answer: Android - Expected Resource of type ID

My solution :

Forget this post

move loading_animation file from anim folder to drawable folder

and loading_animation file :

<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>

and i using this :

               <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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM