The Developer Preview for Android 11 is now available; test it out and share your feedback.

BaselineShift

@Immutable data class BaselineShift
kotlin.Any
   ↳ androidx.ui.text.style.BaselineShift

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

Summary

Public constructors

<init>(multiplier: Float)

import androidx.ui.core.Text
import androidx.ui.text.AnnotatedString
import androidx.ui.text.SpanStyle
import androidx.ui.text.TextStyle
import androidx.ui.text.withStyle

Text(
    style = TextStyle(fontSize = 20.sp),
    text = AnnotatedString {
        append(text = "Hello")
        withStyle(SpanStyle(baselineShift = BaselineShift.Superscript, fontSize = 16.sp)) {
            append("superscript")
            withStyle(SpanStyle(baselineShift = BaselineShift.Subscript)) {
                append("subscript")
            }
        }
    }
)

Inherited extension functions

From androidx.compose
operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Properties

Float

shift the baseline by multiplier * (baseline - ascent)

Companion properties

BaselineShift

Constant for no baseline shift.

BaselineShift

Default baseline shift for subscript

BaselineShift

Default baseline shift for superscript.

Public constructors

<init>

BaselineShift(multiplier: Float)
import androidx.ui.core.Text
import androidx.ui.text.AnnotatedString
import androidx.ui.text.SpanStyle
import androidx.ui.text.TextStyle
import androidx.ui.text.withStyle

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

val annotatedString = AnnotatedString {
    append("Text ")
    withStyle(SpanStyle(baselineShift = BaselineShift.Superscript)) {
        append("Demo")
    }
}
Text(text = annotatedString)
Parameters
multiplier: Float shift the baseline by multiplier * (baseline - ascent)

Properties

multiplier

val multiplier: Float

shift the baseline by multiplier * (baseline - ascent)

Companion properties

None

val None: BaselineShift

Constant for no baseline shift.

Subscript

val Subscript: BaselineShift

Default baseline shift for subscript

Superscript

val Superscript: BaselineShift

Default baseline shift for superscript.