代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n测试Demo\n" />
</LinearLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="点我" />
</RelativeLayout>
即在LinearLayout外面套一个ScrollView即可,而ScrollView里面的内容即可滚动。
运行如下,可以看到一个滚动条: