user1737894
user1737894

Reputation:

variable size text in android

Friends,I am trying to set a text of variable size in my app, but I am not getting the desired result.

msgInside=(TextView)findViewById(R.id.textView2);
msgInside.setTextSize(30);
msgInside.setText("BIG MESSAGE");
msgInside.setTextSize(20);
msgInside.setText("SMALL MESSAGE");

I can only see the SMALL MESSAGE, I need to see both the messages

Upvotes: 0

Views: 239

Answers (4)

Andro Selva
Andro Selva

Reputation: 54322

You need to use spannable String for this purpose. Just try this,

        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);

enter image description here

Upvotes: 3

Renjith
Renjith

Reputation: 5803

You are using the same textview for your both texts. the second text will overwrite your first one.

For your desired result either use seperate texviews or use Spannable String to get seperate fonts, sizes etc.. in a single textview. This is a nice tutorial for Spannable String

Upvotes: 1

Pir Fahim Shah
Pir Fahim Shah

Reputation: 10623

yeah you can't use it double at a time, if u r ineterested in it then make a Reference object of that text view, i think u vl get something different and good.

Upvotes: 0

SBJ
SBJ

Reputation: 4139

use different textview for both text size message... its overright size of text if you use same textview for both message...

msgInside=(TextView)findViewById(R.id.textView2);
msgInside.setTextSize(30);
msgInside.setText("BIG MESSAGE");
msgInside3=(TextView)findViewById(R.id.textView3);
msgInside3.setTextSize(20);
msgInside3.setText("SMALL MESSAGE");

Thanks

Upvotes: 1

Related Questions