Vlad Alexeev
Vlad Alexeev

Reputation: 2214

working with Strings - how can I make "small numbers" in the upper part like in real books - is it possible?

Sorry , my English is not enough to explain clearly what I want, maybe that's why I can't find answer in the Google.

When you use real book - sometimes you have some text there that needs an explanation and after that text you have "*" sign and an explanation at the bottom of the page under a line.

And sometimes it's not a "*", it's a small number at the top of last word. Like "1" , "2" ,etc, and then same explanation at the bottom of the page under a line.

What I need to know - is there any instrument in java/Android SDK to have this numbers to be small and at the top in TextView?

Like, maybe Spanned Strings can do that?

Upvotes: 2

Views: 478

Answers (4)

Brijesh Patel
Brijesh Patel

Reputation: 676

You can Achive this 2 Way.

1) Using SuperscriptSpan:

SpannableString span = new SpannableString("book1");
        span.setSpan(new SuperscriptSpan(), 4, 5,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
txt.setText(span, BufferType.SPANNABLE);

2) Using Html:

txt.setText(Html.fromHtml("book<sup>1</sup>"));

Upvotes: 0

Biraj Zalavadia
Biraj Zalavadia

Reputation: 28484

Tested Demo

public class MainActivity extends Activity {

    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (TextView) findViewById(R.id.textView);
        textView.setText(Html.fromHtml("Hi this demo test for book reading effect <sup>2</sup>"));
    }

}

OutPut:

enter image description here

Upvotes: 2

Henry
Henry

Reputation: 43788

The easiest way to produce such a Spanned is with the Html utility class:

textView.setText(Html.fromHtml("book<sup>1</sup>"));

Upvotes: 3

Timu&#231;in
Timu&#231;in

Reputation: 4673

You can use SubscriptSpan or SuperscriptSpan within a SpannableString.

Upvotes: 2

Related Questions