0% found this document useful (0 votes)
42 views

01.3 Text and Scrolling Views-Es

The document discusses TextView and ScrollView, which are views for displaying text and scrolling content in Android. It covers how to use TextView to display formatted text, link URLs, and set attributes programmatically or in XML. ScrollView is described as a way to scroll long text by wrapping a TextView or layout within it.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

01.3 Text and Scrolling Views-Es

The document discusses TextView and ScrollView, which are views for displaying text and scrolling content in Android. It covers how to use TextView to display formatted text, link URLs, and set attributes programmatically or in XML. ScrollView is described as a way to scroll long text by wrapping a TextView or layout within it.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Android Developer Fundamentals V2

Construya su
primera app

Lesson 1

Text and This work is licensed under a Creative


Android
Android Developer
Developer Fundamentals
Fundamentals V2
V2 Commons Attribution 4.0 International 1
Scrolling Views
License.
1.3 Text and scrolling
views

Text and This work is licensed under a Creative


Android Developer Fundamentals V2 Commons Attribution 4.0 International 2
Scrolling Views
License.
Contents

● TextView
● ScrollView

This work is licensed under a Creative


Text and Commons Attribution 4.0 International
Android Developer Fundamentals V2 3
Scrolling Views License.
TextView

Android Developer Fundamentals V2 4


TextView for text
● TextView is View subclass for single and multi-line text
● EditText is TextView subclass with editable text
● Controlled with layout attributes
● Set text:
○ Statically from string resource in XML
○ Dynamically from Java code and any source

Text and This work is licensed under a Creative


Android Developer Fundamentals V2 Commons Attribution 4.0 International 5
Scrolling Views
License.
Formatting text in string resource
● Use <b> and <i> HTML tags for bold and italics
● Todos las otras etiquetas HTML son ignoradas
● String resources: una linea continua = un parrafo
● \n comienza una nueva línea o párrafo
● Escape apostrophes and quotes with backslash (\", \')
● Escape any non-ASCII characters with backslash (\)
Text and This work is licensed under a Creative
Android Developer Fundamentals V2 Commons Attribution 4.0 International 6
Scrolling Views
License.
Creating TextView in XML

<TextView android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/my_story"/>

Text and This work is licensed under a Creative


Android Developer Fundamentals V2 Commons Attribution 4.0 International 7
Scrolling Views
License.
Common TextView attributes
android:text—text to display
android:textColor—color of text
android:textAppearance—predefined style or theme
android:textSize—text size in sp
android:textStyle—normal, bold, italic, or bold|italic
android:typeface—normal, sans, serif, or monospace
android:lineSpacingExtra—extra space between lines in sp
Text and This work is licensed under a Creative
Android Developer Fundamentals V2 Commons Attribution 4.0 International 8
Scrolling Views
License.
Formatting active web links
<string name="article_text">... www.rockument.com ...</string>

<TextView
android:id="@+id/article"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="@string/article_text"/> Don’t use HTML
for a web link in
free-form text
autoLink values:"web", "email", "phone", "map", "all"

Text and This work is licensed under a Creative


Android Developer Fundamentals V2 Commons Attribution 4.0 International 9
Scrolling Views
License.
Creating TextView in Java code
TextView myTextview = new TextView(this);
myTextView.setWidth(LayoutParams.MATCH_PARENT);
myTextView.setHeight(LayoutParams.WRAP_CONTENT);
myTextView.setMinLines(3);
myTextView.setText(R.string.my_story);
myTextView.append(userComment);

Text and This work is licensed under a Creative


Android Developer Fundamentals V2 Commons Attribution 4.0 International 10
Scrolling Views
License.
ScrollView

Android Developer Fundamentals V2 11


Qué pasa con grandes cantidades de texto?

● Noticias, articulos, etc…


● Para desplazar un TextView, incrustarlo en ScrollView
● Only one View element (usually TextView) allowed in a
ScrollView
● To scroll multiple elements, use one ViewGroup (such as
LinearLayout) within the ScrollView

Text and This work is licensed under a Creative


Android Developer Fundamentals V2 Commons Attribution 4.0 International 12
Scrolling Views
License.
ScrollView for scrolling content
● ScrollView is a subclass of FrameLayout
● Mantiene todo el contenido en la memoria
● No es bueno para textos largos, diseños complejos.
● No anidar multiples scrolling views
● Use HorizontalScrollView for horizontal scrolling
● Use a RecyclerView for lists

Text and This work is licensed under a Creative


Android Developer Fundamentals V2 Commons Attribution 4.0 International 13
Scrolling Views
License.
ScrollView layout with one TextView
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/article_subheading">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.../>

</ScrollView>
Text and This work is licensed under a Creative
Android Developer Fundamentals V2 Commons Attribution 4.0 International 14
Scrolling Views
License.
ScrollView layout with a view group
<ScrollView ...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/article_subheading"
.../>

<TextView
android:id="@+id/article" ... />
</LinearLayout>
</ScrollView>

Text and This work is licensed under a Creative


Android Developer Fundamentals V2 Commons Attribution 4.0 International 15
Scrolling Views
License.
ScrollView with image and button
<ScrollView...>
One child of ScrollView
<LinearLayout...>
which can be a layout
<ImageView.../>
<Button.../> Children of the layout

<TextView.../>
</LinearLayout>
</ScrollView>
Text and This work is licensed under a Creative
Android Developer Fundamentals V2 Commons Attribution 4.0 International 16
Scrolling Views
License.
Learn more
Developer Documentation:
● TextView
● ScrollView and HorizontalScrollView
● String Resources
Other:
● Android Developers Blog: Linkify your Text!
● Codepath: Working with a TextView

This work is licensed under a Creative


Text and
Android Developer Fundamentals V2 Commons Attribution 4.0 International 17
Scrolling Views
License.
What's Next?

● Concept Chapter: 1.3 Text and scrolling views


● Practical: 1.3 Text and scrolling views

This work is licensed under a Creative


Text and
Android Developer Fundamentals V2 Commons Attribution 4.0 International 18
Scrolling Views
License.
END

Android Developer Fundamentals V2 19

You might also like