竖直滚动:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="128dp"
android:text="123"/>
<Button
android:layout_width="match_parent"
android:layout_height="128dp"
android:text="123"/>
<Button
android:layout_width="match_parent"
android:layout_height="128dp"
android:text="123"/>
<Button
android:layout_width="match_parent"
android:layout_height="128dp"
android:text="123"/>
<Button
android:layout_width="match_parent"
android:layout_height="128dp"
android:text="123"/>
<Button
android:layout_width="match_parent"
android:layout_height="128dp"
android:text="123"/>
<Button
android:layout_width="match_parent"
android:layout_height="128dp"
android:text="123"/>
</LinearLayout>
</ScrollView>
水平滚动:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">//隐藏滚动条
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
//此处可以摆放N个控件,当超出范围时会有垂直滚动条
</LinearLayout>
</HorizontalScrollView>
本文详细介绍了Android中竖直和水平滚动视图的实现方式,包括ScrollView和HorizontalScrollView的使用,以及如何设置滚动条的可见性。通过具体的XML布局代码示例,展示了如何创建包含多个按钮的滚动区域。
1592

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



