Reputation: 2214
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
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
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:
Upvotes: 2
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
Reputation: 4673
You can use SubscriptSpan or SuperscriptSpan within a SpannableString.
Upvotes: 2