当前位置: 首页>>代码示例>>Java>>正文


Java ScaleXSpan类代码示例

本文整理汇总了Java中android.text.style.ScaleXSpan的典型用法代码示例。如果您正苦于以下问题:Java ScaleXSpan类的具体用法?Java ScaleXSpan怎么用?Java ScaleXSpan使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScaleXSpan类属于android.text.style包,在下文中一共展示了ScaleXSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applySpacing

import android.text.style.ScaleXSpan; //导入依赖的package包/类
private void applySpacing() {
    if (this == null || this.originalText == null) return;
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < originalText.length(); i++) {
        builder.append(originalText.charAt(i));
        if (i + 1 < originalText.length()) {
            builder.append("\u00A0");
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int i = 1; i < builder.toString().length(); i += 2) {
            finalText.setSpan(new ScaleXSpan((spacing + 1) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    super.setText(finalText, BufferType.SPANNABLE);
    setSelection(finalText.length());
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:19,代码来源:ChangeTextSpaceEditText.java

示例2: applyLetterSpacing

import android.text.style.ScaleXSpan; //导入依赖的package包/类
/**
 * 字距为任何字符串(技术上,一个简单的方法为CharSequence不使用)的TextView
 */
private void applyLetterSpacing() {
    if (this == null || this.originalText == null) return;
    StringBuilder builder = new StringBuilder();
    for(int i = 0; i < originalText.length(); i++) {
        String c = ""+ originalText.charAt(i);
        builder.append(c.toLowerCase());
        if(i+1 < originalText.length()) {
            builder.append("\u00A0");
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if(builder.toString().length() > 1) {
        for(int i = 1; i < builder.toString().length(); i+=2) {
            finalText.setSpan(new ScaleXSpan((letterSpacing+1)/10), i, i+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    super.setText(finalText, BufferType.SPANNABLE);
}
 
开发者ID:bigjelly,项目名称:ShaddockVideoPlayer,代码行数:22,代码来源:SpacingTextView.java

示例3: applyLetterSpacing

import android.text.style.ScaleXSpan; //导入依赖的package包/类
private SpannableString applyLetterSpacing(String text) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < text.length(); i++) {
        builder.append(text.charAt(i));
        if (i + 1 < text.length() && !isEmojiCharacter(text.charAt(i))) {//avoid adding the blank code between the emoji code
            builder.append("\u00A0");
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int i = 1; i < builder.toString().length(); i += 2) {
            if (builder.toString().toCharArray()[i] == 160) {//avoid breaking emoji code, u00A0 is text space
                finalText.setSpan(new ScaleXSpan((mLetterSpace + 1) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return finalText;
}
 
开发者ID:MaYatKit,项目名称:Rotatable-Scalable-Font,代码行数:19,代码来源:WidgetTextContent.java

示例4: applyKerning

import android.text.style.ScaleXSpan; //导入依赖的package包/类
/**
 * The algorithm which applies the kerning to the {@link TextView}
 */
private void applyKerning() {
    if (mOriginalText == null) {
        return;
    }
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < mOriginalText.length(); i++) {
        builder.append(mOriginalText.charAt(i));
        if (i + 1 < mOriginalText.length()) {
            builder.append("\u00A0");
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int i = 1; i < builder.toString().length(); i += 2) {
            finalText.setSpan(new ScaleXSpan((mKerningFactor) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    super.setText(finalText, BufferType.SPANNABLE);
}
 
开发者ID:aritraroy,项目名称:KerningViews,代码行数:23,代码来源:KerningTextView.java

示例5: getSpacedOutString

import android.text.style.ScaleXSpan; //导入依赖的package包/类
private SpannableStringBuilder getSpacedOutString(CharSequence text) {
    final SpannableStringBuilder builder =  new SpannableStringBuilder();
    final int textLength = text.length();
    int lastSpaceIndex = -1;

    //Insert a space in front of all characters upto the last character
    //Scale the space without scaling the character to preserve font appearance
    for (int i = 0; i < textLength - 1; i++) {
        builder.append(text.charAt(i));
        builder.append(" ");
        lastSpaceIndex += 2;
        builder.setSpan(new ScaleXSpan(proportion), lastSpaceIndex, lastSpaceIndex + 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    //Append the last character
    if (textLength != 0) builder.append(text.charAt(textLength - 1));

    return builder;
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:21,代码来源:SpacedEditText.java

示例6: testSpacing

import android.text.style.ScaleXSpan; //导入依赖的package包/类
/**
 * 1. Tests whether the content is set to the expected value.
 * 2. Tests whether the original content is set to the original value.
 * 3. Tests that the styles applied have the expected propotion
 * 4. Tests that the styles have been applied only on the spaces to preserve fonts appearance.
 * @param expectedSpacedText
 * @param expectedOriginalText
 * @param editText
 */
private void testSpacing(String expectedSpacedText, String expectedOriginalText,
                         SpacedEditText editText) {
    final Editable editable = editText.getText();
    final ScaleXSpan[] spans = editable.getSpans(0, editText.length(), ScaleXSpan.class);

    assertEquals(expectedSpacedText, editable.toString());
    assertEquals(expectedOriginalText, editText.getUnspacedText().toString());

    for (ScaleXSpan span: spans){
        assertEquals(spacingPropotion, span.getScaleX());

        final int spanStart = editable.getSpanStart(span);
        final int spanEnd = editable.getSpanEnd(span);

        assertEquals(" ", editable.toString().substring(spanStart, spanEnd));
    }
}
 
开发者ID:crashlytics,项目名称:digits-android,代码行数:27,代码来源:SpacedEditTextTest.java

示例7: applyLetterSpacing

import android.text.style.ScaleXSpan; //导入依赖的package包/类
private void applyLetterSpacing() {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < originalText.length(); i++) {
        builder.append(originalText.charAt(i));
        if (i + 1 < originalText.length()) {
            builder.append('\u00A0');
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int i = 1; i < builder.toString().length(); i += 2) {
            finalText.setSpan(new ScaleXSpan((letterSpacing + 1.0F) / 10.0F), i, i + 1, SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    super.setText(finalText, BufferType.SPANNABLE);
}
 
开发者ID:callmesusheel,项目名称:yelli,代码行数:17,代码来源:LetterSpacingTextView.java

示例8: getSpacedOutString

import android.text.style.ScaleXSpan; //导入依赖的package包/类
private SpannableStringBuilder getSpacedOutString(CharSequence text) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    int textLength = text.length();
    int lastSpaceIndex = -1;

    //Insert a space in front of all characters upto the last character
    //Scale the space without scaling the character to preserve font appearance
    for (int i = 0; i < textLength - 1; i++) {
        builder.append(text.charAt(i));
        builder.append(" ");
        lastSpaceIndex += 2;
        builder.setSpan(new ScaleXSpan(mProportion), lastSpaceIndex, lastSpaceIndex + 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    //Append the last character
    if (textLength != 0) builder.append(text.charAt(textLength - 1));

    return builder;
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:21,代码来源:SpacedEditText.java

示例9: testSpacing

import android.text.style.ScaleXSpan; //导入依赖的package包/类
/**
 * 1. Tests whether the content is set to the expected value.
 * 2. Tests whether the original content is set to the original value.
 * 3. Tests that the styles applied have the expected proportion
 * 4. Tests that the styles have been applied only on the spaces to preserve fonts appearance.
 */
private void testSpacing(String expectedSpacedText, String expectedOriginalText,
                         SpacedEditText editText) {
    final Editable editable = editText.getText();
    final ScaleXSpan[] spans = editable.getSpans(0, editText.length(), ScaleXSpan.class);

    assertEquals(expectedSpacedText, editable.toString());
    assertEquals(expectedOriginalText, editText.getUnspacedText().toString());

    for (ScaleXSpan span : spans) {
        assertEquals(SPACING_PROPORTION, span.getScaleX());

        final int spanStart = editable.getSpanStart(span);
        final int spanEnd = editable.getSpanEnd(span);

        assertEquals(" ", editable.toString().substring(spanStart, spanEnd));
    }
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:24,代码来源:SpacedEditTextTest.java

示例10: scale_x_should_add_only_one_span

import android.text.style.ScaleXSpan; //导入依赖的package包/类
@Test
public void scale_x_should_add_only_one_span() {
    spanBuilder.scaleX(range, INTEGER_ARG)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(ScaleXSpan.class));
}
 
开发者ID:yombunker,项目名称:SpanEZ,代码行数:9,代码来源:SpanEZTest.java

示例11: scaleXSize

import android.text.style.ScaleXSpan; //导入依赖的package包/类
/**
 * @see android.text.style.ScaleXSpan#ScaleXSpan(float)
 */
public static Span scaleXSize(@FloatRange(from = 0.0) final float proportion) {
    return new Span(new SpanBuilder() {
        @Override
        public Object build() {
            return new ScaleXSpan(proportion);
        }
    });
}
 
开发者ID:neworld,项目名称:spanner,代码行数:12,代码来源:Spans.java

示例12: scaleX

import android.text.style.ScaleXSpan; //导入依赖的package包/类
public TextDecorator scaleX(final float proportion, final String... texts) {
  int index;

  for (String text : texts) {
    if (content.contains(text)) {
      index = content.indexOf(text);
      decoratedContent.setSpan(new ScaleXSpan(proportion), index, index + text.length(), flags);
    }
  }

  return this;
}
 
开发者ID:nntuyen,项目名称:text-decorator,代码行数:13,代码来源:TextDecorator.java

示例13: onCreate

import android.text.style.ScaleXSpan; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_demo_spannable);

    TextView tv_1 = findViewById(R.id.tv_1);
    TextView tv_2 = findViewById(R.id.tv_2);

    String content = "目前有{numHospital}家医院{numSeller}位咨询师";
    content = content.replace("{numHospital}", "28").replace("{numSeller}", "325");

    //普通TextView
    tv_1.setText(content);

    //spannable处理过的TextView

    Spanned s = Html.fromHtml(content);
    int index0 = content.indexOf("前有")+2;
    int index1 = content.indexOf("家医院") + 3;
    int index2 = content.indexOf("位咨");

    String color = "#79d2be";
    SpannableString msp = new SpannableString(s);
    msp.setSpan(new RelativeSizeSpan(1.25f), index0, index1-3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //0.5f表示默认字体大小的一半
    msp.setSpan(new RelativeSizeSpan(1.2f), index1,index2 , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //0.5f表示默认字体大小的一半
    msp.setSpan(new ForegroundColorSpan(Color.parseColor(color)), index0, index1-3,  Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //设置前景色
    msp.setSpan(new ForegroundColorSpan(Color.parseColor(color)),index1,index2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //设置前景色
    msp.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), index0, index1-3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //斜体
    msp.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), index1,index2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //斜体
    msp.setSpan(new ScaleXSpan(0.9f), index0, index1-3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    msp.setSpan(new ScaleXSpan(0.9f), index1,index2 , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv_2.setText(msp);
}
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:34,代码来源:SpannableActivity.java

示例14: onCreate

import android.text.style.ScaleXSpan; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final SpannableStringBuilder ssb = new SpannableStringBuilder();
    final int flag = Spannable.SPAN_EXCLUSIVE_EXCLUSIVE;
    int start;
    int end;

    // Regular text
    ssb.append("This text is normal, but ");

    // Bold text
    start = ssb.length();
    ssb.append("this text is bold");
    end = ssb.length();
    ssb.setSpan(new StyleSpan(Typeface.BOLD), start, end, flag);

    // Inline image
    ssb.append('\n');
    start = end + 1;
    ssb.append('\uFFFC'); // Unicode replacement character
    end = ssb.length();
    ssb.setSpan(new ImageSpan(this, R.mipmap.ic_launcher), start, end, flag);

    // Stretched text
    start = end;
    ssb.append("This text is wide");
    end = ssb.length();
    ssb.setSpan(new ScaleXSpan(2f), start, end, flag);

    // Assign to TextView
    final TextView tv = (TextView) findViewById(R.id.textView);
    tv.setText(ssb);
}
 
开发者ID:IanGClifton,项目名称:auid2,代码行数:40,代码来源:MainActivity.java

示例15: setUpScaleXSpan

import android.text.style.ScaleXSpan; //导入依赖的package包/类
private static void setUpScaleXSpan(Span span, SpannableString ss, int start, int end) {
    float scaleX = span.getScaleX();
    if (Float.floatToRawIntBits(scaleX) != 0) {
        ss.setSpan(
            new ScaleXSpan(scaleX),
            start,
            end,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
开发者ID:lawloretienne,项目名称:Trestle,代码行数:11,代码来源:Trestle.java


注:本文中的android.text.style.ScaleXSpan类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。