【问题标题】:Display of decimal numbers十进制数的显示
【发布时间】:2015-11-24 12:15:35
【问题描述】:

我看到一些 Android 应用程序显示十进制数字,其中小数部分的字体较小,即使它们看起来在单个 TextView 中,如下所示:

我想知道如何制作这样的东西。

【问题讨论】:

标签: android


【解决方案1】:

尝试将HTML字符串设置为TextView

String text = "831<sup>69</sup>";
textView.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);

【讨论】:

    【解决方案2】:

    这是在 java 文件中执行此操作的一种方法:

    textview.setText(Html.fromHtml("<b>" + title + "</b>" + "<small>" + description + "</small>"));
    

    使用spans

    例子:

    final SpannableStringBuilder sb = new SpannableStringBuilder("your text here");
    
    // Span to set text color to some RGB value
    final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(158, 158, 158)); 
    
    // Span to make text bold
    final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); 
    
    // Set the text color for first 4 characters
    sb.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 
    
    // make them also bold
    sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 
    
    yourTextView.setText(sb);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多