【例1-7】 文本标签组件示例
设计由标题和正文组成的界面,翻看的文字超过一屏。

教学视频
打开res\values下的strings.xml,添加属性为“hello”的元素项的文本内容。
<string name="hello">
故今日之责任,不在他人,而全在我少年。少年智则国智,少年富则国富;少年强则国强,少年独立则国独立;
少年自由则国自由;少年进步则国进步;少年胜于欧洲,则国胜于欧洲;少年雄于地球,则国雄于地球。
红日初升,其道大光。河出伏流,一泻汪洋。潜龙腾渊,鳞爪飞扬。乳虎啸谷,百兽震惶。
鹰隼试翼,风尘翕张。奇花初胎,矞矞皇皇。干将发硎,有作其芒。天戴其苍,地履其黄。
纵有千古,横有八荒。前途似海,来日方长。美哉我少年中国,与天不老!壮哉我中国少年,与国无疆!
</string>
布局文件textview.xml,需要将字体调大一些,才能看到翻页效果。
<?xml version="1.0" encoding="utf-8"?>
<!--【例1-7】设计一个由标题和正文组成的文本框组件 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
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="30sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarStyle="insideInset">
<TextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="2dp"
android:text="@string/hello"
android:textSize="28sp" />
</ScrollView>
</LinearLayout>
控制文件MainActivity.java源代码
package com.example.chap01;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textview); //【例1-7】
}
}

