字符串以相同的T​​extView不同尺寸 [英] Different size of strings in the same TextView

查看:137
本文介绍了字符串以相同的T​​extView不同尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView里面有一个数字(变量)和一个字符串,我怎么能给头号尺寸比字符串大? 在code:

I have a textView inside with a number (variable) and a string, how can I give the number one size larger than the string? the code:

    TextView size = (TextView)convertView.findViewById(R.id.privarea_list_size);
    if (ls.numProducts != null) {
        size.setText(ls.numProducts + " " + mContext.getString(R.string.products));


    }

我想ls.numproducts的大小从文本的与众不同。怎么办?

I want ls.numproducts has a size different from the rest of the text. how to do?

推荐答案

使用一个Spannable字符串

Use a Spannable String

 String s= "Hello Everyone";
 SpannableString ss1=  new SpannableString(s);
 ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size
 ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color
 TextView tv= (TextView) findViewById(R.id.textview);
 tv.setText(ss1); 

快照

您可以利用空间分割字符串,并添加跨度为您所需要的字符串。

You can split string using space and add span to the string you require.

 String[] each;
 String s= "Hello Everyone";  
 for(int i=0;i<s.length();i++)
 {
     each = s.split("\\s");         
 }

现在适用范围为字符串,并添加到相同TextView的。

Now apply span to the string and add the same to textview.

这篇关于字符串以相同的T​​extView不同尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆