首页 > 其他 > 详细

ScrollView使用笔记

时间:2014-03-20 18:32:17      阅读:482      评论:0      收藏:0      [点我收藏+]
  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

示意图:
bubuko.com,布布扣

ScrollView使用笔记,布布扣,bubuko.com

ScrollView使用笔记

原文:http://blog.csdn.net/kaiwii/article/details/21626199

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!