Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Any ideas?</p> </blockquote> <p>When using the default <code>progressDrawable</code> or a <code>progressDrawable</code> set through a theme all will be ok as in the constructor for the <code>RatingBar</code>(its superclass <code>ProgressBar</code> to be more precise) widget a method will be called to "make tiles" from that drawable. When using the <code>setProgressDrawable</code> method this doesn't happen and if you pass a simple <code>BitmapDrawable</code> or a <code>LayerDrawable</code>(with simple <code>BitmapDrawables</code>) that <code>Drawable</code> will simply be stretched to cover the widget's background area(what you see know).</p> <p>In order to make it work you would need to manually do what the <code>RatingBar</code> does at start, create the tiles along with the <code>ClipDrawables</code> that it uses. I've written a method for this, following the source code of the <code>ProgressBar</code> widget:</p> <pre><code>private Drawable buildRatingBarDrawables(Bitmap[] images) { final int[] requiredIds = { android.R.id.background, android.R.id.secondaryProgress, android.R.id.progress }; final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 }; Drawable[] pieces = new Drawable[3]; for (int i = 0; i &lt; 3; i++) { ShapeDrawable sd = new ShapeDrawable(new RoundRectShape( roundedCorners, null, null)); BitmapShader bitmapShader = new BitmapShader(images[i], Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); sd.getPaint().setShader(bitmapShader); ClipDrawable cd = new ClipDrawable(sd, Gravity.LEFT, ClipDrawable.HORIZONTAL); if (i == 0) { pieces[i] = sd; } else { pieces[i] = cd; } } LayerDrawable ld = new LayerDrawable(pieces); for (int i = 0; i &lt; 3; i++) { ld.setId(i, requiredIds[i]); } return ld; } </code></pre> <p>Then you would use the <code>LayerDrawable</code> returned by this method with the <code>setProgressDrawable</code> method. The <code>RatingBar</code> set its width multiplying the width of one of the state bitmaps with the number of stars, so in order to show the right amount of stars this has to be calculated as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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