0

I have tried all code but i can't find solution how use this (GIF)image in my progessbar

XML file

<ProgressBar
    android:id="@+id/progressBar"
    style="@style/GenericProgressIndicator"
    android:layout_width="fill_parent"
    android:layout_height="200px"
    android:layout_centerInParent="true"
    android:visibility="visible"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:indeterminateDrawable="@drawable/animation" >
</ProgressBar>

JAVA File

ProgressBar  bar=(ProgressBar)findViewById(R.id.progressBar);

Want to use this image in progress bar Want to use this image in progress bar

seggy
  • 1,176
  • 2
  • 18
  • 38

3 Answers3

3

You don't need to use ProgressBar to show a GIF, unless you want to use special functionality that ProgressBar provides (does not look like it).

It's enough to use simple ImageView and some image library that supports GIFs (eg Glide).

Rafal Zawadzki
  • 963
  • 6
  • 15
1

this is a trick instead of a full solution i load the gif as an image in alert dialog box with transparent background and show this alert dialog at start of process and dismiss it at the end.

However have a look at this too: Custom circular ProgressBar with image in center

Community
  • 1
  • 1
Ak9637
  • 990
  • 6
  • 12
  • Thanx for your interest can i set GIF image in alert dialog box? – seggy Nov 17 '16 at 13:10
  • yes but you need to create a custom dialog which contains an imageview and the root layout has transparent background.You can then set the source of this imageview to your local gif – Ak9637 Nov 17 '16 at 13:13
-1
  1. First Convert your Gif image to png Slice image sequence.
  2. Declare Your Progress bar as Image view.
<ImageView
             android:id="@+id/ivProgress"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center"
             android:visibility="visible" />
  1. Create a .xml file in a drawable folder using your .png sequence image those are generated from gif.
<?xml version="1.0" encoding="utf-8"?>
            <animation-list    xmlns:android="http://schemas.android.com/apk/res/android"
            android:oneshot="false">
        <item
            android:drawable="@mipmap/wblod_0"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_1"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_2"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_3"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_4"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_5"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_6"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_7"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_8"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_9"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_10"
            android:duration="40" />
        <item
            android:drawable="@mipmap/wblod_11"
            android:duration="40" />
        </animation-list>
  1. In your activity set code like this.
private AnimationDrawable animationDrawable;
private ImageView mProgressBar;
mProgressBar.setBackgroundResource(R.drawable.loading_web_animation);
animationDrawable =(AnimationDrawable)mProgressBar.getBackground();
mProgressBar.setVisibility(View.VISIBLE);
animationDrawable.start();
mProgressBar.setVisibility(View.GONE);
animationDrawable.stop();
Rahul
  • 3,293
  • 2
  • 31
  • 43