ScrollView使用札记

ScrollView使用笔记
  1. ScrollView的实际大小超过手机屏幕的显示范围(在Y轴上);如下图所示,手机屏幕相当于一个滑动窗沿Y轴方向在整个ScrollView中滑动;
  2. ScrollView只能含有一个子View(当然这View可以是一个Group,如Layout,即可含有多个View);所以,可以这样理解,这个包含的子View的显示范围即ScrollView的全部显示范围;
布局XML示例:
说明:
由此可见,自定义ScrollView(com.example.photowallfallsdemo.MyScrollView)下,仅仅含有一个子View(LinearLayout)。其中,这个子View(LinearLayout)可以含有三个子View(LinearLayout)
如下所示:
<com.example.photowallfallsdemo.MyScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/first_column"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>

        <LinearLayout
            android:id="@+id/second_column"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>

        <LinearLayout
            android:id="@+id/third_column"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>
    </LinearLayout>

</com.example.photowallfallsdemo.MyScrollView>

      3.各主要参数及函数使用:
注意比较b与c两点
a、获取手机屏幕显示范围相对于整个ScrollView的Y轴偏移量:
myScrollView.getScrollY();
b、获取整个ScrollView的高度
(在2点中已经说过,ScrollView只能含有一个子View,且这个子View的大小即ScrollView的大小
scrollLayout = getChildAt(0);//获取MyScrollView的唯一一个子View
scrollLayout.getHeight();
c、获取手机显示范围的高度:
getHeight();//相对于MyScrollView

示意图:
ScrollView使用札记