Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I ended up using the <a href="http://blog.mediarain.com/2011/04/android-custom-progressbar-with-rounded-corners/" rel="nofollow">Custom Progress Bar with Round Corners</a> as a foundation to mine that Harry Joy recommended. However, if you want the same functionality that android's SDK version, such has <a href="http://developer.android.com/reference/android/widget/ProgressBar.html" rel="nofollow">intermediate</a> from the ProgressBar class I had to make some changes. The changes I have made enable an intermediate drawable to be defined and animated.</p> <p>Make sure you follow the instructions <a href="http://blog.mediarain.com/2011/04/android-custom-progressbar-with-rounded-corners/" rel="nofollow">here</a>, but replace the RoundProgress class with this:</p> <pre><code>public class RoundProgress extends RelativeLayout { private ImageView progressDrawableImageView; private ImageView trackDrawableImageView; private ImageView backGroundImageView; private double max = 100; private AttributeSet attrs2 ; private Transformation mTransformation; private AlphaAnimation mAnimation; private int mBehavior; private int mDuration; private Interpolator mInterpolator; private static Context ctx; private int bgResource; public int getMax() { Double d = new Double(max); return d.intValue(); } public double getMaxDouble() { return max; } public void setMax(int max) { Integer maxInt = new Integer(max); maxInt.doubleValue(); this.max = max; } public void setMax(double max) { this.max = max; } public RoundProgress(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.round_progress, this); setup(context, attrs); } protected void setup(Context context, AttributeSet attrs) { attrs2 = attrs; ctx = context; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundProgress); //setBackgroundResource(R.drawable.custom_loading_bg); backGroundImageView = (ImageView) findViewById(R.id.background_image_view); backGroundImageView.setBackgroundResource(R.drawable.custom_loading_bg); final String xmlns="http://schemas.android.com/apk/res/com.digiphd.prospec"; bgResource = attrs.getAttributeResourceValue(xmlns, "progressDrawable", 0); progressDrawableImageView = (ImageView) findViewById( R.id.progress_drawable_image_view); progressDrawableImageView.setBackgroundResource(bgResource); int trackResource = attrs.getAttributeResourceValue(xmlns, "track", 0); trackDrawableImageView = (ImageView) findViewById(R.id.track_image_view); trackDrawableImageView.setBackgroundResource(trackResource); int progress = attrs.getAttributeIntValue(xmlns, "progress", 0); setProgress(progress); int max = attrs.getAttributeIntValue(xmlns, "max", 100); setMax(max); int numTicks = attrs.getAttributeIntValue(xmlns, "numTicks", 0); a.recycle(); ProgressBarOutline outline = new ProgressBarOutline(context); //addView(outline); } public void setProgress(Integer value) { setProgress((double) value); } public void setProgress(double value) { ClipDrawable drawable = (ClipDrawable) progressDrawableImageView.getBackground(); double percent = (double) value/ (double)max; int level = (int)Math.floor(percent*10000); drawable.setLevel(level); } public void setIntermediate(boolean t) { if(t){ progressDrawableImageView.setBackgroundResource(R.drawable.custom_intermediate_bg); startAnimation(); }else{ progressDrawableImageView.clearAnimation(); progressDrawableImageView.setBackgroundResource(bgResource); } } /** * &lt;p&gt;Start the indeterminate progress animation.&lt;/p&gt; */ void startAnimation() { int visibility = getVisibility(); if (visibility != VISIBLE) { return; } Log.d("INTERMEDIATE","ANIMATION START!"); mDuration = 1000; if (mInterpolator == null) { mInterpolator = new LinearInterpolator(); } mTransformation = new Transformation(); mAnimation = new AlphaAnimation(0.0f, 1.0f); mAnimation.setRepeatMode(Animation.REVERSE); mAnimation.setRepeatCount(Animation.INFINITE); mAnimation.setDuration(mDuration); mAnimation.setInterpolator(mInterpolator); mAnimation.setStartTime(Animation.START_ON_FIRST_FRAME); progressDrawableImageView.startAnimation(mAnimation); } } </code></pre> <p>Now in your activity, you can just call .setIntermediate(true or false) when required.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload