Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8887833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:54:22+00:00 2026-06-14T21:54:22+00:00

I’ve been scratching my head over this for a long time now and searched

  • 0

I’ve been scratching my head over this for a long time now and searched for an answer without any luck!
It seems to be trivial, but as far as I know, it isn’t.

I use a listview in my Android application where every item (view) displays a spinning ProgressBar before the
content is loaded and displayed (the content is retrieved through http calls and json, so it may take a while to process).
The problem is that the spinning progress bars rotates independently of each other, thus creating the effect of a whirling
chaos instead of a syncronised row of good-looking loading markers.

I’ve tried everything i could come up with… not recycling the ProgressBar in getView()… have only one instance of the same ProgressBar…
resetting the ProgressBars android:progress whenever the list items gets visible (via onScroll() in the activity)… etc,
but since they start to spin in creation time (when getView gets called in the adapter) they will never have the same cycle sync.

enter image description here

Any suggestions are welcome!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:54:23+00:00Added an answer on June 14, 2026 at 9:54 pm

    EDIT: Now works perfectly! – inserted animation listener call setStartOffset() back to 0 after the first repeat so that it doesn’t keep “jumping” randomly.


    I found a working solution for this issue, which works by timing the animation to the current system milliseconds. It’s a bit of a hack, as it uses reflection to get the mAnimation field in ProgressBar. That being said, this field has remained in place in the Android sources since it was created (works up to 4.2).

    Create the android.widget.SyncedProgressBar class, and use it instead of ProgressBar in your .xml files. It essentially makes the animation start at the beginning of the animation duration. You can also play around with setDuration(500) to verify that it works (the progress wheel will spin really quickly). Hope this helps!

    package android.widget;
    
    import android.annotation.SuppressLint;
    import android.content.Context;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.View;
    import android.view.animation.AlphaAnimation;
    import android.view.animation.Animation;
    import android.view.animation.Animation.AnimationListener;
    
    import java.lang.reflect.Field;
    
    /**
    * @author Oleg Vaskevich
    *
    */
    public class SyncedProgressBar extends ProgressBar {
    
        public SyncedProgressBar(Context context) {
            super(context);
            modifyAnimation();
        }
    
        public SyncedProgressBar(Context context, AttributeSet attrs) {
            super(context, attrs);
            modifyAnimation();
        }
    
        public SyncedProgressBar(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            modifyAnimation();
        }
    
        @Override
        public void setVisibility(int v) {
            super.setVisibility(v);
            modifyAnimation();
        }
    
        @SuppressLint("NewApi")
        @Override
        protected void onVisibilityChanged(View changedView, int visibility) {
            super.onVisibilityChanged(changedView, visibility);
            modifyAnimation();
        }
    
        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            modifyAnimation();
        }
    
        @Override
        public synchronized void setIndeterminate(boolean indeterminate) {
            super.setIndeterminate(indeterminate);
            modifyAnimation();
        }
    
        public void modifyAnimation() {
            Field mAnim;
            try {
                mAnim = ProgressBar.class.getDeclaredField("mAnimation");
                mAnim.setAccessible(true);
                AlphaAnimation anim = (AlphaAnimation) mAnim.get(this);
                if (anim == null)
                    return;
    
                // set offset to that animations start at same time
                long duration = anim.getDuration();
                long timeOffset = System.currentTimeMillis() % duration;
                anim.setDuration(duration);
                anim.setStartOffset(-timeOffset);
                anim.setAnimationListener(new AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }
    
                    @Override
                    public void onAnimationRepeat(Animation animation) {
                        animation.setStartOffset(0);
                    }
    
                    @Override
                    public void onAnimationEnd(Animation animation) {
                    }
                });
            } catch (Exception e) {
                Log.d("SPB", "that didn't work out...", e);
                return;
            }
            postInvalidate();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.