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

示意图:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值