一.ScrollView控件简介:
这个控件分为垂直方向的和水平方向的,分别为ScrollView和HorizotalScrollView。
二.写一个既可以垂直滑动又可以水平滑动的ScrollView例子:
1.话不多说,直接上代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="这是最上边的位置" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="800dp"
android:text="这是一个超出屏幕高度的地方" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是最左边的位置" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="300dp"
android:text="这是一个超出屏幕宽度的地方" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
2.话不多说,直接上结果gif: