seggy
seggy

Reputation: 1196

How to use gif image in progress bar

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

Upvotes: 0

Views: 7980

Answers (3)

Rahul
Rahul

Reputation: 3349

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

Upvotes: -1

Rafal Zawadzki
Rafal Zawadzki

Reputation: 901

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

Upvotes: 3

Ak9637
Ak9637

Reputation: 990

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

Upvotes: 1

Related Questions