代码如下:
<?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里面的内容即可滚动。
运行如下,可以看到一个滚动条:

本文介绍了一种在Android布局中实现滚动效果的方法,通过在LinearLayout外部包裹ScrollView,使得长文本内容能够滚动显示。示例代码展示了如何设置ScrollView和TextView属性,以适应屏幕大小并提供滚动功能。
3425

被折叠的 条评论
为什么被折叠?



