0

Is there a way I can have gradient drawable for my rating view I am OK with if I need to draw those "ZZZZZ" in onDraw method instead of defining in xml because they need to be smaller to larger. So instead of extending RatingBar class I tried extending textview class and planning to use onTouch (Move) event to get the rating from 1-5. Correct me if you think extending RatingBar class would be still better idea. So far I was able to get different text size by using -

 for (int i = 0; i < text.length(); i++) {
        SpannableStringBuilder sb;
        fontSize += incrementFontBy;
        paint.setTextSize(fontSize);
        setTypeface(typeFace);
        sb.setSpan(new AbsoluteSizeSpan(fontSize), i, character.length, 0);
        setText(sb);
    }

Also, I am not sure if spannable gradient is possible as I move my finger but I know I can have gradient using paint object. For testing purpose I did -

paint.setShader(new LinearGradient(0,0,0,getPaint().getTextSize()/2,Color.BLACK,Color.GREEN, Shader.TileMode.CLAMP));

I haven't implemented onTouch event yet. But I am trying to find all my possibilities before I get into onTouch event. Things that I am seeking for

  • Can spannable text have gradient(looking at Dynamic Spannable currently)
  • Can Rating view have custom drawing (drawing that is small to large and gradient on touch

Expectation

enter image description here

Result so far

enter image description here

Alex
  • 1,052
  • 1
  • 11
  • 22

1 Answers1

0

Extending the RatingBar would probably be a better idea. Just create new style with your custom drawables and add that style to the style attribute of the RatingBar.

A more detailed approach can be found here.

Community
  • 1
  • 1
Harsh Pandey
  • 831
  • 7
  • 12