我在SpannableStringBuilder中几乎没有重叠的跨度。我想定义将它们实施到文本的顺序。跨度有int旗
int SPAN_PRIORITY = 16711680;
int SPAN_PRIORITY_SHIFT = 16;
我该如何使用它们?有多少级别可跨度优先级?什么是默认一个?
要定义 priority
,您必须利用位魔术:
int priority = 123; // Should be in range [0..255].
int spanFlags = 0;
// ...
// Cleaning up priority bits.
spanFlags &= ~Spannable.SPAN_PRIORITY;
// Injecting priority bits.
spanFlags |= (priority << Spannable.SPAN_PRIORITY_SHIFT) & Spannable.SPAN_PRIORITY;
// ...
sb.setSpan(what, start, end, spanFlags);