Class AbsoluteSizeSpan

All Implemented Interfaces:
ParcelableSpan, UpdateAppearance, UpdateLayout, Parcelable

public class AbsoluteSizeSpan extends MetricAffectingSpan implements ParcelableSpan
A span that changes the size of the text it's attached to.

For example, the size of the text can be changed to 55dp like this:


 SpannableString string = new SpannableString("Text with absolute size span");
 string.setSpan(new AbsoluteSizeSpan(55, true), 10, 23, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  • Constructor Details

    • AbsoluteSizeSpan

      public AbsoluteSizeSpan(int size)
      Set the text size to size physical pixels.
    • AbsoluteSizeSpan

      public AbsoluteSizeSpan(int size, boolean scaled)
      Set the text size to size physical pixels, or to size device-independent pixels if scaled is true.
    • AbsoluteSizeSpan

      public AbsoluteSizeSpan(@NonNull Parcel src)
      Creates an AbsoluteSizeSpan from a parcel.
  • Method Details

    • getSpanTypeId

      public int getSpanTypeId()
      Description copied from interface: ParcelableSpan
      Return a special type identifier for this span class.
      Specified by:
      getSpanTypeId in interface ParcelableSpan
    • writeToParcel

      public void writeToParcel(@NonNull Parcel dest, int flags)
      Description copied from interface: Parcelable
      The subclass implements the method to flatten its contents by calling the methods of Parcel for its primitive values.
      Specified by:
      writeToParcel in interface Parcelable
      Parameters:
      dest - the parcel to write the object's data to
      flags - the flags about how the object should be written
    • getSize

      public int getSize()
      Get the text size. This is in physical pixels if isScaled() returns false or in device-independent pixels if isScaled() returns true.
      Returns:
      the text size, either in physical pixels or device-independent pixels.
      See Also:
    • isScaled

      public boolean isScaled()
      Returns whether the size is in device-independent pixels or not, depending on the scaled flag passed in AbsoluteSizeSpan(int, boolean)
      Returns:
      true if the size is in device-independent pixels, false otherwise
      See Also:
    • updateMeasureState

      public void updateMeasureState(@NonNull TextPaint paint)
      Description copied from class: MetricAffectingSpan
      Classes that extend MetricAffectingSpan implement this method to update the text formatting in a way that can change the width or height of characters.
      Specified by:
      updateMeasureState in class MetricAffectingSpan
      Parameters:
      paint - the paint used for measuring the text