Spacing between the stars of a rating bar?

后端 未结 2 1503
小鲜肉
小鲜肉 2020-12-10 18:22

ho can I set a spacing beween the stars? Thats my ratingbar:

ratingBar = (RatingBar) inflater.inflate(R.layout.ratingbar, null);
ratingBar.setLayoutParams(ne         


        
相关标签:
2条回答
  • 2020-12-10 18:47

    You have to add the padding to the png itself. While there is something known as an Inset Drawable (http://developer.android.com/guide/topics/resources/drawable-resource.html#Inset) that you could wrap your drawable into, the code for 'tileify'-ing (as referred to in the android source code) doesn't handle the case of drawable being an inset drawable, and hence doesn't tile the image.

    Here's the tilefy method (in ProgressBar.java, which is the ancestor to RatingBar.java: https://gist.github.com/CyanogenMod/android_frameworks_base/blob/gingerbread/core/java/android/widget/ProgressBar.java)

    private Drawable tileify(Drawable drawable, boolean clip) {
    
        if (drawable instanceof LayerDrawable) {
            LayerDrawable background = (LayerDrawable) drawable;
            final int N = background.getNumberOfLayers();
            Drawable[] outDrawables = new Drawable[N];
    
            for (int i = 0; i < N; i++) {
                int id = background.getId(i);
                outDrawables[i] = tileify(background.getDrawable(i),
                        (id == R.id.progress || id == R.id.secondaryProgress));
            }
    
            LayerDrawable newBg = new LayerDrawable(outDrawables);
    
            for (int i = 0; i < N; i++) {
                newBg.setId(i, background.getId(i));
            }
    
            return newBg;
    
        } else if (drawable instanceof StateListDrawable) {
            StateListDrawable in = (StateListDrawable) drawable;
            StateListDrawable out = new StateListDrawable();
            int numStates = in.getStateCount();
            for (int i = 0; i < numStates; i++) {
                out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
            }
            return out;
    
        } else if (drawable instanceof BitmapDrawable) {
            final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
            if (mSampleTile == null) {
                mSampleTile = tileBitmap;
            }
    
            final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
    
            final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                    Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
            shapeDrawable.getPaint().setShader(bitmapShader);
    
            return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                    ClipDrawable.HORIZONTAL) : shapeDrawable;
        }
    
        return drawable;
    }
    
    0 讨论(0)
  • 2020-12-10 19:10

    There's no simple way to modify the padding between images, better save time and simply add some space with any available image editor.

    0 讨论(0)
提交回复
热议问题