3

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>
Community
  • 1
  • 1

2 Answers2

8

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

Community
  • 1
  • 1
shusheng007
  • 389
  • 4
  • 5
  • see example code In [link](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html). animation.xml file must be in **res/drawable/** folder NOT res/anim/. and set background resource using **R.drawable.animation** NOT R.anim.animation. I don't know history but i think need to adapt this solution. – illusionJJ Aug 10 '16 at 07:46
  • What does mean plus sign? @shusheng007 – illusionJJ Aug 10 '16 at 07:50
2

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"/>
Community
  • 1
  • 1