Adnan
Adnan

Reputation: 8729

Complex Android TextView

I'm getting name and a reference number from the database. Now, I want to show data like this

enter image description here

Here A is the name & 1 is the reference number. Already, I have a layout like

<ScrollView><RelativeLayout></RelativeLayout></ScrollView>

Already, There are other contents in the RelativeLayout. So, is this possible to show data like this in a RelativeLayout. So my question is

1) is this possible to show data like this ?

2) If yes, then how can I achieve that ? I will be happy, If you give an example.

Upvotes: 2

Views: 258

Answers (3)

Andro Selva
Andro Selva

Reputation: 54322

Or there is another Way. The Spannable StringBuilder.

Try this,

  textview=(TextView)findViewById(R.id.text);
            SpannableStringBuilder spanSupScript = new SpannableStringBuilder("A1 \nB2");
            spanSupScript.setSpan(new SuperscriptSpan(), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spanSupScript.setSpan(new RelativeSizeSpan((float)0.75), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spanSupScript.setSpan(new SuperscriptSpan(), 5, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spanSupScript.setSpan(new RelativeSizeSpan((float)0.75), 5, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spanSupScript.setSpan(new StyleSpan(Typeface.BOLD), 0, spanSupScript.length(), 0);
            textview.setTextSize(16);
            textview.setText(spanSupScript);

Use a TextView, do the above code, and get the output as follows,

enter image description here

Upvotes: 1

Naresh
Naresh

Reputation: 3179

You can add two more TextView to the relative layout and with the help of the tag (As mentioned by @Armaan Stranger ) and add the text dynamically.

Upvotes: 0

Armaan Stranger
Armaan Stranger

Reputation: 3130

Try this:

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("A<sup><small>1</small></sup>"));

It will Create superscript of given number in tag.

Hope it Helps!!

Upvotes: 2

Related Questions