如何在Android中定义Spannable的顺序(setPriority)

时间:2017-09-01 14:54:53

标签: android spannable

我在SpannableStringBuilder中有很少的重叠跨度。我想定义它们将实现到Text的顺序。 Spannable有int标志

int SPAN_PRIORITY = 16711680;
int SPAN_PRIORITY_SHIFT = 16;

我该如何使用它们? Spannable优先级有多少级别? 什么是默认值?

1 个答案:

答案 0 :(得分:1)

要定义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);