Android - imageview.setBackgroundResource issues -
i have image view have set 400dp(width) , 300dp(height). image view used in list view loading images url. during loading of images, show progess bar animation set this:
imageview.setbackgroundresource(r.drawable.progress); final animationdrawable startanimation = (animationdrawable) imageview .getbackground(); startanimation.start();
once image finished loading , ll remove animation , set loaded image shown below:
imageview.setbackgroundresource(0); imageview.setimagebitmap(bitmap);
but probelm is, animation taking specified width , height, ie 400dp , 300dp respectively, how can reduce size of animation drawable alone ?
my animation file: progress.xml
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/anim_black" android:oneshot="false" > <item android:drawable="@drawable/frame_1" android:duration="100"/> <item android:drawable="@drawable/frame_2" android:duration="100"/> <item android:drawable="@drawable/frame_3" android:duration="100"/> <item android:drawable="@drawable/frame_4" android:duration="100"/> <item android:drawable="@drawable/frame_5" android:duration="100"/> <item android:drawable="@drawable/frame_6" android:duration="100"/> <item android:drawable="@drawable/frame_7" android:duration="100"/> <item android:drawable="@drawable/frame_8" android:duration="100"/> <item android:drawable="@drawable/frame_9" android:duration="100"/> <item android:drawable="@drawable/frame_10" android:duration="100"/> <item android:drawable="@drawable/frame_11" android:duration="100"/> <item android:drawable="@drawable/frame_12" android:duration="100"/> </animation-list>
frame 1, frame 2 ....frame 12 png files got splitting gif image.
you should use setimageresource
animation in case. background image scaled fit whole image. need chage scaletype
before starting animation , after image loaded well.
imageview.setimageresource(r.drawable.progress); imageview.setscaletype(scaletype.center); final animationdrawable startanimation = (animationdrawable) imageview.getdrawable(); startanimation.start(); // , once image loaded imageview.setimagebitmap(bitmap); imageview.setscaletype(scaletype.center_inside);