我在应用程序中试图设置一个文本变量的大小,但是没有得到预期的效果。使用了以下代码:
msgInside=(TextView)findViewById(R.id.textView2);
msgInside.setTextSize(30);
msgInside.setText("BIG MESSAGE");
msgInside.setTextSize(20);
msgInside.setText("SMALL MESSAGE");
我只看到SMALL MESSAGE,没有BIG MESSAGE,我需要这两个都出现,怎么实现啊?谢谢。
你应该使用spannable字符串,如下:
TextView text=(TextView)findViewById(R.id.text);
Spannable span = new SpannableString("Hi this is Android");
span.setSpan(new RelativeSizeSpan(0.8f), 0 , 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setTextSize(20);
text.setText(span);
在你的text中使用了相同的textview。第二个text会重写第一个。