BaselineShift


The amount by which the text is shifted up or down from current the baseline.

import androidx.compose.material.Text
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.BaselineShift
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp

Text(
    fontSize = 20.sp,
    text =
        buildAnnotatedString {
            append(text = "Hello")
            withStyle(SpanStyle(baselineShift = BaselineShift.Superscript, fontSize = 16.sp)) {
                append("superscript")
                withStyle(SpanStyle(baselineShift = BaselineShift.Subscript)) {
                    append("subscript")
                }
            }
        }
)
import androidx.compose.material.Text
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.BaselineShift
import androidx.compose.ui.text.withStyle

val annotatedString = buildAnnotatedString {
    append("Text ")
    withStyle(SpanStyle(baselineShift = BaselineShift.Superscript)) { append("Demo") }
}
Text(text = annotatedString)

Summary

Public companion properties

BaselineShift

Constant for no baseline shift.

Cmn
BaselineShift

Default baseline shift for subscript

Cmn
BaselineShift

Default baseline shift for superscript.

Cmn

Public constructors

BaselineShift(multiplier: Float)
Cmn

Public properties

Float

shift the baseline by multiplier * (baseline - ascent)

Cmn

Public companion properties

None

val NoneBaselineShift

Constant for no baseline shift.

Subscript

val SubscriptBaselineShift

Default baseline shift for subscript

Superscript

val SuperscriptBaselineShift

Default baseline shift for superscript.

Public constructors

BaselineShift

BaselineShift(multiplier: Float)
Parameters
multiplier: Float

shift the baseline by multiplier * (baseline - ascent)

Public properties

multiplier

val multiplierFloat

shift the baseline by multiplier * (baseline - ascent)