01.3 Text and scrolling views
01.3 Text and scrolling views
Build your
first app
Lesson 1
● TextView
● ScrollView
<TextView android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/my_story"/>
<TextView
android:id="@+id/article"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Don’t use HTML
android:autoLink="web"
for a web link in
android:text="@string/article_text"/>
free-form text
autoLink values:"web", "email", "phone", "map",
"all"
Text and This work is licensed under a
Android Developer Scrolling Views
Creative Commons Attribution 4.0 9
Fundamentals V2 International License
Creating TextView in Java code
TextView myTextview = new TextView(this);
myTextView.setWidth(LayoutParams.MATCH_PARENT
);
myTextView.setHeight(LayoutParams.WRAP_CONTEN
T);
myTextView.setMinLines(3);
myTextView.setText(R.string.my_story);
myTextView.append(userComment);
Text and This work is licensed under a
Android Developer Scrolling Views
Creative Commons Attribution 4.0 10
Fundamentals V2 International License
ScrollView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.../>
</ScrollView>
Text and This work is licensed under a
Android Developer Scrolling Views
Creative Commons Attribution 4.0 14
Fundamentals V2 International 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
Android Developer Scrolling Views
Creative Commons Attribution 4.0 15
Fundamentals V2 International License
ScrollView with image and
button
<ScrollView...>
One child of ScrollView
<LinearLayout...> which can be a layout
<ImageView.../>
Children of the layout
<Button.../>
<TextView.../>
</LinearLayout>
</ScrollView>
Text and This work is licensed under a
Android Developer Scrolling Views
Creative Commons Attribution 4.0 16
Fundamentals V2 International License
Learn more
Developer Documentation:
● TextView
● ScrollView and HorizontalScrollView
● String Resources
Other:
● Android Developers Blog: Linkify your Text!
● Codepath: Working with a TextView