Java Code Examples for android.text.style.AlignmentSpan#Standard

The following examples show how to use android.text.style.AlignmentSpan#Standard . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlActivity.java    From Markwon with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Object getSpans(
        @NonNull MarkwonConfiguration configuration,
        @NonNull RenderProps renderProps,
        @NonNull HtmlTag tag) {

    final Layout.Alignment alignment;

    // html attribute without value, <align center></align>
    if (tag.attributes().containsKey("center")) {
        alignment = Layout.Alignment.ALIGN_CENTER;
    } else if (tag.attributes().containsKey("end")) {
        alignment = Layout.Alignment.ALIGN_OPPOSITE;
    } else {
        // empty value or any other will make regular alignment
        alignment = Layout.Alignment.ALIGN_NORMAL;
    }

    return new AlignmentSpan.Standard(alignment);
}
 
Example 2
Source File: AlignmentSpanActivity.java    From advanced-textview with Apache License 2.0 5 votes vote down vote up
private void appendText(CharSequence text, Layout.Alignment align) {
  if (text == null || text.toString().trim().length() == 0) {
    return;
  }

  AlignmentSpan span = new AlignmentSpan.Standard(align);
  SpannableString spannableString = new SpannableString(text);
  spannableString.setSpan(span, 0, text.length(), 0);

  if (textView.length() > 0) {
    textView.append("\n\n");
  }
  textView.append(spannableString);
}
 
Example 3
Source File: SpanEZ.java    From SpanEZ with Apache License 2.0 4 votes vote down vote up
@Override
public StyleEZ alignCenter(@NonNull ParagraphLocator paragraph) {
    AlignmentSpan centerSpan = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
    addMultipleSpan(paragraph, centerSpan);
    return this;
}
 
Example 4
Source File: SpanEZ.java    From SpanEZ with Apache License 2.0 4 votes vote down vote up
@Override
public StyleEZ alignEnd(@NonNull ParagraphLocator paragraph) {
    AlignmentSpan oppositeSpan = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE);
    addMultipleSpan(paragraph, oppositeSpan);
    return this;
}
 
Example 5
Source File: SpanEZ.java    From SpanEZ with Apache License 2.0 4 votes vote down vote up
@Override
public StyleEZ alignStart(@NonNull ParagraphLocator paragraph) {
    AlignmentSpan normalSpan = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL);
    addMultipleSpan(paragraph, normalSpan);
    return this;
}
 
Example 6
Source File: SpanOptions.java    From AndroidSpan with Apache License 2.0 4 votes vote down vote up
public SpanOptions addAlignmentSpan(Layout.Alignment align) {
    AlignmentSpan.Standard span = new AlignmentSpan.Standard(align);
    listSpan.add(span);
    return this;
}
 
Example 7
Source File: AndroidSpan.java    From AndroidSpan with Apache License 2.0 2 votes vote down vote up
/**
 * 标准文本对齐样式
 *
 * @param text
 * @param align "ALIGN_CENTER"、"ALIGN_NORMAL" 或"ALIGN_OPPOSITE"中的之一
 * @return
 */
public AndroidSpan drawAlignmentSpan(String text, Layout.Alignment align) {
    AlignmentSpan.Standard span = new AlignmentSpan.Standard(align);
    drawSpan(text, span);
    return this;
}