365連休

にわかのandroidとかの開発メモ。

Android Studio 4.1 定義済みSpanを調査してみた

TextViewのsetTextにStringではなくSpannableを設定すると、細かい書式設定ができて便利。

だが、定義済みのSpanにどんなものがあるのか、網羅的リファレンスの日本語訳がないため、android.text.style.*のパッケージサマリを意訳してみた。

 

developer.android.com


 

Interfaces
APILevel Name Reference 意訳
1 AlignmentSpan Span that allows defining the alignment of text at the paragraph level. 

段落のテキストの配置を変更するSpan

コンストラクタ AlignmentSpan.Standard( Layout.Alignment alignment )

1 LeadingMarginSpan A paragraph style affecting the leading margin.  段落のリーダーマージンを変更するSpan
8 LeadingMarginSpan.LeadingMarginSpan2 An extended version of LeadingMarginSpan, which allows the implementor to specify the number of lines of the paragraph to which this object is attached that the "first line of paragraph" margin width will be applied to.  LeadingMarginSpanの拡張版で、実装者は段落の行数を指定し、"段落の最初の行"の余白の幅を適用可能にする
1 LineBackgroundSpan Used to change the background of lines where the span is attached to.  行の背景を変更するSpan
1 LineHeightSpan The classes that affect the line height of paragraph should implement this interface.  段落の行の高さを変更するSpan
5 LineHeightSpan.WithDensity The classes that affect the line height of paragraph with respect to density, should implement this interface.  密度に関して段落の行の高さを変更するSpan
1 ParagraphStyle The classes that affect paragraph-level text formatting implement this interface.  段落レベルの書式設定を行うクラスのInterface
1 TabStopSpan Paragraph affecting span that changes the position of the tab with respect to the leading margin of the line.  段落の行の先頭余白に対してタブ位置を変更する段落Span
3 UpdateAppearance The classes that affect character-level text in a way that modifies their appearance when one is added or removed must implement this interface.  文字レベルのテキストの外観に影響を与えるクラスのInterface。変更時にinvalidate()が必要なもの
1 UpdateLayout The classes that affect character-level text formatting in a way that triggers a text layout update when one is added or removed must implement this interface.  文字レベルのテキストのサイズに影響を与えるクラスのInterface。変更時にrequestLayout()が必要なもの
1 WrapTogetherSpan   LineHeightSpanなどのベースInterface

 

Classes
APILevel Name Reference 意訳
1 AbsoluteSizeSpan A span that changes the size of the text it's attached to.  テキストサイズを変更するSpan。
1 AlignmentSpan.Standard Default implementation of the AlignmentSpan.  AlignmentSpanのデフォルト実装。
1 BackgroundColorSpan Changes the background color of the text to which the span is attached.  背景色を変更するSpan
1 BulletSpan A span which styles paragraphs as bullet points (respecting layout direction).  段落を箇条書きにするSpan(レイアウト方向を考慮する)
1

abstract

CharacterStyle

The classes that affect character-level text formatting extend this class.  文字レベルの書式設定を行うクラスのベースクラス
1

abstract

ClickableSpan

If an object of this type is attached to the text of a TextView with a movement method of LinkMovementMethod, the affected spans of text can be selected.  LinkMovementMethodが使用されている場合に、テキストをクリック可能にし、その動作を設定する
1 DrawableMarginSpan A span which adds a drawable and a padding to the paragraph it's attached to.  段落にDrawableとPaddingを追加するSpan
1

abstract

DynamicDrawableSpan

Span that replaces the text it's attached to with a Drawable that can be aligned with the bottom or with the baseline of the surrounding text. 

テキストをDrawableに置き換えるSpan。Drawableは下端またはベースラインに揃えられる。

ImageSpanのベースクラス。

14 EasyEditSpan Provides an easy way to edit a portion of text.  テキストの一部を簡単に編集できます!
1 ForegroundColorSpan Changes the color of the text to which the span is attached.  テキストの色を変更するSpan
1 IconMarginSpan Paragraph affecting span, that draws a bitmap at the beginning of a text.  段落レベルのSpanで、テキストの先頭にbitmapを描画する
1 ImageSpan Span that replaces the text it's attached to with a Drawable that can be aligned with the bottom or with the baseline of the surrounding text.  テキストをDrawableに置き換えるSpan。Drawableは下端またはベースラインに揃えられる。
1 LeadingMarginSpan.Standard The standard implementation of LeadingMarginSpan, which adjusts the margin but does not do any rendering.  マージンを調整するがレンダリングを行わないLeadingMarginSpanの標準実装
29 LineBackgroundSpan.Standard Default implementation of the LineBackgroundSpan, which changes the background color of the lines to which the span is attached.  行の背景色を変更するLineBackgroundSpanの標準実装
29 LineHeightSpan.Standard Default implementation of the LineHeightSpan, which changes the line height of the attached paragraph.  段落の行の高さを変更するLineHeightSpanの標準実装
17 LocaleSpan Changes the Locale of the text to which the span is attached.  テキストのロケールを変更するSpan
1 MaskFilterSpan Span that allows setting a MaskFilter to the text it's attached to.  テキストにMaskFilterを設定するSpan
1

abstract

MetricAffectingSpan

The classes that affect character-level text formatting in a way that changes the width or height of characters extend this class.  文字レベルのサイズに影響を与えるクラスのベースクラス
1 QuoteSpan A span which styles paragraphs by adding a vertical stripe at the beginning of the text (respecting layout direction).  段落レベルのSpanで、テキストの先頭に縦じまを追加する
1 RelativeSizeSpan Uniformly scales the size of the text to which it's attached by a certain proportion.  テキストサイズを相対サイズで変更するSpan
1

abstract

ReplacementSpan

  DynamicDrawableSpan, ImageSpanのベースクラス
1 ScaleXSpan Scales horizontally the size of the text to which it's attached by a certain factor.  特定条件で、テキストサイズを水平方向に拡大縮小するSpan
1 StrikethroughSpan A span that strikes through the text it's attached to.  テキストを取り消し線を追加するSpan
1 StyleSpan Span that allows setting the style of the text it's attached to.  テキストのスタイル(斜体太字)を設定するSpan
1 SubscriptSpan The span that moves the position of the text baseline lower.  ベースラインを低くするSpan
14 SuggestionSpan Holds suggestion candidates for the text enclosed in this span.  サジェスト候補を保持するSpan
1 SuperscriptSpan The span that moves the position of the text baseline higher.  ベースラインを高くするSpan
1 TabStopSpan.Standard The default implementation of TabStopSpan that allows setting the offset of the tab stop from the leading margin of the first line of text.  最初の行の先頭余白からのタブストップのオフセットを設定できるTabStopSpanの標準実装
1 TextAppearanceSpan Sets the text appearance using the given TextAppearance attributes.  TextAppearance属性を使用してテキストの外観を設定するSpan
21 TtsSpan A span that supplies additional meta-data for the associated text intended for text-to-speech engines.  テキスト読み上げエンジン向けのメタデータを追加するSpan
21 TtsSpan.Builder<C extends Builder<?>> A simple builder for TtsSpans. 
21 TtsSpan.CardinalBuilder A builder for TtsSpans of type TtsSpan.TYPE_CARDINAL. 
21 TtsSpan.DateBuilder A builder for TtsSpans of type TtsSpan.TYPE_DATE. 
21 TtsSpan.DecimalBuilder A builder for TtsSpans of type TtsSpan.TYPE_DECIMAL. 
21 TtsSpan.DigitsBuilder A builder for TtsSpans of type TtsSpan.TYPE_DIGITS. 
21 TtsSpan.ElectronicBuilder A builder for TtsSpans of type TtsSpan.TYPE_ELECTRONIC. 
21 TtsSpan.FractionBuilder A builder for TtsSpans of type TtsSpan.TYPE_FRACTION. 
21 TtsSpan.MeasureBuilder A builder for TtsSpans of type TtsSpan.TYPE_MEASURE. 
21 TtsSpan.MoneyBuilder A builder for TtsSpans of type TtsSpan.TYPE_MONEY. 
21 TtsSpan.OrdinalBuilder A builder for TtsSpans of type TtsSpan.TYPE_ORDINAL. 
21 TtsSpan.SemioticClassBuilder<C extends SemioticClassBuilder<?>> A builder for TtsSpans, has setters for morphosyntactic features. 
21 TtsSpan.TelephoneBuilder A builder for TtsSpans of type TtsSpan.TYPE_TELEPHONE. 
21 TtsSpan.TextBuilder A builder for TtsSpans of type TtsSpan.TYPE_TEXT. 
21 TtsSpan.TimeBuilder A builder for TtsSpans of type TtsSpan.TYPE_TIME. 
21 TtsSpan.VerbatimBuilder A builder for TtsSpans of type TtsSpan.TYPE_VERBATIM. 
1 TypefaceSpan Span that updates the typeface of the text it's attached to.  テキストのTypefaceを更新するSpan
1 UnderlineSpan A span that underlines the text it's attached to.  アンダーラインを追加するSpan
1 URLSpan Implementation of the ClickableSpan that allows setting a url string.  ClickableSpanを継承したURL形式テキスト用のSpan

 

 

参考リンク

Spannable使用方法 公式

developer.android.com

 

 

 

※上記はhttps://developer.android.com/reference/android/text/style/package-summaryの意訳である。

Android開発者向けドキュメントを意訳してみる。 - 365連休

意訳元https://developer.android.com/ライセンス解釈
ソースコードから抽出されたドキュメントやコードはAndroid Open Source Projectの優先ライセンスであるApache 2.0 licenseが適用され、それ以外のコンテンツはCC BY 2.5が適用されている。
よって、ページ全体の意訳についてはCC BY 2.5における翻案行為、ページ内のコード転載についてはApache 2.0 licenseにおける頒布行為にあたると解釈している。