Android Developer Fundamentals V 2 Build your first
Android Developer Fundamentals V 2 Build your first app Lesson 1 Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 1
1. 3 Text and scrolling views Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 2
Contents ● Text. View ● Scroll. View Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 3
Text. View for text ● Text. View is View subclass for single and multi-line text ● Edit. Text is Text. View subclass with editable text ● Controlled with layout attributes ● Set text: ○ Statically from string resource in XML ○ Dynamically from Java code and any source Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 4
Formatting text in string resource ● Use <b> and <i> HTML tags for bold and italics ● All other HTML tags are ignored ● String resources: one unbroken line = one paragraph ● n starts a new a line or paragraph ● Escape apostrophes and quotes with backslash (", ') ● Escape any non-ASCII characters with backslash () Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 5
Creating Text. View in XML <Text. View android: id="@+id/textview" android: layout_width="match_parent" android: layout_height="wrap_content" android: text="@string/my_story"/> Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 6
Common Text. View attributes android: text—text to display android: text. Color —color of text android: text. Appearance —predefined style or theme android: text. Size —text size in sp android: text. Style —normal, bold, italic, or bold|italic android: typeface —normal, sans, serif, or monospace android: line. Spacing. Extra —extra space between lines in sp Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 7
Formatting active web links <string name="article_text">. . . www. rockument. com. . . </string> <Text. View android: id="@+id/article" android: layout_width="wrap_content" android: layout_height="wrap_content" android: auto. Link="web" android: text="@string/article_text"/> Don’t use HTML for a web link in free-form text auto. Link values: "web", "email", "phone", "map", "all" Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 8
Creating Text. View in Java code Text. View my. Textview = new Text. View(this); my. Text. View. set. Width(Layout. Params. MATCH_PARENT); my. Text. View. set. Height(Layout. Params. WRAP_CONTENT); my. Text. View. set. Min. Lines(3); my. Text. View. set. Text(R. string. my_story); my. Text. View. append(user. Comment); Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 9
Scroll. View Android Developer Fundamentals V 2 10
What about large amounts of text? ● News stories, articles, etc… ● To scroll a Text. View, embed it in a Scroll. View ● Only one View element (usually Text. View) allowed in a Scroll. View ● To scroll multiple elements, use one View. Group (such as Linear. Layout) within the Scroll. View Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 11
Scroll. View for scrolling content ● Scroll. View is a subclass of Frame. Layout ● Holds all content in memory ● Not good for long texts, complex layouts ● Do not nest multiple scrolling views ● Use Horizontal. Scroll. View for horizontal scrolling ● Use a Recycler. View for lists Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 12
Scroll. View layout with one Text. View <Scroll. View android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_below="@id/article_subheading"> <Text. View android: layout_width="wrap_content" android: layout_height="wrap_content". . . /> </Scroll. View> Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 13
Scroll. View layout with a view group <Scroll. View. . . <Linear. Layout android: layout_width="match_parent" android: layout_height="wrap_content" android: orientation="vertical"> <Text. View android: id="@+id/article_subheading". . . /> <Text. View android: id="@+id/article". . . /> </Linear. Layout> </Scroll. View> Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 14
Scroll. View with image and button <Scroll. View. . . > One child of Scroll. View which can be a layout <Linear. Layout. . . > <Image. View. . . /> Children of the layout <Button. . . /> <Text. View. . . /> </Linear. Layout> </Scroll. View> Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 15
Count. Down. Timer my. Timer; my. Timer=new Count. Down. Timer(50000, 1000) { @Override public void on. Tick(long millis. Until. Finished) { }; } @Override public void on. Finish() { } my. Timer. start(); Android Developer Fundamentals V 2 Text and Scrolling Views This work is licensed under a Creative Commons Attribution 4. 0 International License. 16
END Android Developer Fundamentals V 2 17
- Slides: 17