开发者

can the layout of text in android views be controlled?

开发者 https://www.devze.com 2023-02-24 17:02 出处:网络
I am looking to format text line by line in a text view or similar. I want to be able to have line by line justifcation and formatting, almost like a word document (though nothing like as 开发者_如何学

I am looking to format text line by line in a text view or similar. I want to be able to have line by line justifcation and formatting, almost like a word document (though nothing like as 开发者_如何学Pythonextensive)

I basically need to be able to have a continuous document with some parts right justified, some parts centered. Some bold, some not and some with a coloured background and some white. Also alowing the user to choose font.

Can someone recommend an decent approach to this please.

thanks


TextView/EditText operates on fairly rich text described by the various style span objects here: http://developer.android.com/reference/android/text/style/package-summary.html

For example you can use this to build text containing those various style spans: http://developer.android.com/reference/android/text/SpannableStringBuilder.html

SpannableStringBuilder is-a CharSequence, so it can be set as the text in a TextView. Though more often you probably just want to use TextView.getEditableText() to return the Editable interface to the text inside of the text view which allows you to modify its contents including style spans.

TextView supports most of what you are asking for through style spans, though justification is applied per-paragraph and not per-line. (Per-line is weird... I don't think even Word does such a thing?)


I would recommend using multiple TextViews. Possibly, one for each line if you really need the text that different. You can customize each one however you want fairly easily. If you haven't already, take a look at the documentation: http://developer.android.com/reference/android/widget/TextView.html
Then, you could use a RelativeLayout or a LinearLayout to position them however you need. Just ask if you have any other questions.

0

精彩评论

暂无评论...
验证码 换一张
取 消