【例1-7】设计一个由标题和正文组成的文本框组件程序,并且翻看的文字超过一屏

打开res\values下的strings.xml源代码,添加属性为“hello”的元素项的文本内容
<string name="hello">
\n青春不是年华,而是心境;青春不是桃面、丹唇、柔膝,而是深沉的意志、恢宏的想像、炽热的感情;青春是生命的深泉涌流。
\n青春气贯长虹,勇锐盖过怯弱,进取压倒苟安。如此锐气,二十后生有之,六旬男子则更多见。年岁有加,并非垂老;理想丢弃,方堕暮年。
\n岁月悠悠,衰微只及肌肤;热忱抛却,颓唐必致灵魂。忧烦、惶恐、丧失自信,定使心灵扭曲,意气如灰。
\n无论年届花甲,抑或二八芳龄,心中皆有生命之欢乐,奇迹之诱惑,孩童般天真久盛不衰。人的心灵应如浩淼瀚海,只有不断接纳美好、希望、欢乐、勇气和力量的百川,才能青春永驻、风华长存。
\n一旦心海枯竭,锐气便被冰雪覆盖,玩世不恭、自暴自弃油然而生,即使年方二十,实已垂垂老矣;然则只要虚怀若谷,让喜悦、达观、仁爱充盈其间,你就有望在八十高龄告别尘寰时仍觉年轻。
</string>
布局文件textview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title"
android:textAlignment="center"
android:textSize="24sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/news_item_content_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="2dp"
android:text="@string/hello"
android:textSize="22sp" />
</ScrollView>
</LinearLayout>
控制文件MainActivity.java源代码
package com.example.chap01;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
//与教材的android.support.v7.app.AppCompatActivity不同
public class MainActivity extends AppCompatActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.textview);
}
}

