Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I scale multiple spans using SpannableStringBuilder?

I have this working, but redundant, code:

feedbackView.text = SpannableStringBuilder()
    .scale(.6f) { italic { append(getString(R.string.suggestion_prefix)) } }
    .scale(.6f) { append("\n\n") }
    .scale(.6f) { bold { append(s) } }

How would I refactor it so there is only one call to .scale()?

When I try this, only the first string is scaled:

feedbackView.text = SpannableStringBuilder()
    .scale(.6f, { italic { append(getString(R.string.suggestion_prefix)) } })
    .append("\n\n")
    .bold { append(s) }

I have not been able to figure out the syntax to include everything in the lambda argument to scale().

like image 969
Ellen Spertus Avatar asked Mar 09 '26 07:03

Ellen Spertus


1 Answers

You can put everything inside one scale lambda.

feedbackView.text = SpannableStringBuilder()
    .scale(.6f) {
        italic { append(getString(R.string.suggestion_prefix)) }
        .append("\n\n")
        .bold { append(s) }
     }
like image 68
Merov Avatar answered Mar 11 '26 20:03

Merov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!