`

ScrollView滚动效果

阅读更多

ScrollView也是一个Layout布局,可以让它内部的数据显示不下的时候出现滚动条,要注意的是不能在ScrollView中放多个组 件,如果放了多个组件,会出现如下错误:ERROR/AndroidRuntime(271): Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child (ScrollView只能包裹一个直接子元素)

我们看一个例子:

<?xml version="1.0" encoding="utf-8"?>

    <ScrollView android:id="@+id/ScrollView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:stretchColumns="0" xmlns:android="http://schemas.android.com/apk/res/android">

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:text="色彩透明度测试" android:textSize="18dip"
android:layout_span="2" android:layout_gravity="center"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>

            </TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#ff00ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#ff00ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#ee00ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#ee00ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#dd00ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#dd00ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#cc00ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#cc00ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#bb00ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#bb00ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#aa00ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#aa00ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#9900ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#9900ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#8800ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#8800ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#7700ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#7700ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#6600ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#6600ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#5500ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#5500ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#4400ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#4400ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#3300ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#3300ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#2200ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#2200ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#1100ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#1100ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:background="#0000ff00"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
<TextView android:text="#0000ff00" android:background="#000"
android:textSize="30dip" android:textColor="#fff"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</TextView>
</TableRow>

            <TextView android:text="色彩透明度测试" android:textSize="18dip"
android:gravity="center_horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>

        </TableLayout>
</ScrollView>

例子的显示效果:

image

向下滚屏后的截图:

image 

来自: http://hi.baidu.com/xiechengfa/blog/item/5da7c803fbe6e313738da5cb.html

分享到:
评论

相关推荐

    Android平台下使用ScrollView滚动效果代码

    本篇文章将深入探讨如何在Android应用中实现ScrollView的滚动效果。 首先,我们来了解ScrollView的基本用法。在XML布局文件中,你可以像这样添加一个ScrollView: ```xml &lt;ScrollView xmlns:android=...

    SCrollView自动滚动视图

    当检测到ScrollView滚动到底部或顶部时,我们会将contentOffset重置为初始位置,这样用户就会看到内容重新开始滚动,形成循环。 UIPageControl是另一个在这个项目中可能用到的UI控件。UIPageControl通常配合...

    ScrollView 的滚动事件监听

    OnScrollChangedListener提供了当ScrollView滚动时触发的方法,而OnGlobalLayoutListener则在视图树的布局完成时被调用,这在某些情况下可以用来检测ScrollView是否可见,从而决定是否开始监听滚动。 1. **...

    自定义动画框架实现ScrollView滚动动画

    以下将详细讲解如何实现一个自定义动画框架,以及如何在ScrollView滚动过程中实现子控件的不同动画效果。 首先,我们需要理解ScrollView的基本工作原理。ScrollView是一个可滚动的布局容器,它允许用户在内容超过...

    安卓scrollview动画滚动到顶部

    在Android开发中,ScrollView是一个非常常用的布局控件,它允许用户在内容超出屏幕时通过滚动查看更多的信息。本文将深入探讨如何实现一个ScrollView动画滚动到顶部的功能,这在很多应用场景中都非常有用,例如用户...

    Android scrollview 滚动条

    ScrollView通常用于包裹其他视图,如LinearLayout、RelativeLayout等,以实现内容的滚动效果。滚动条则是ScrollView的一个重要组成部分,它为用户提供可视化的滚动指示,帮助他们了解当前视图的位置以及可滚动的范围...

    uniapp-scrollview实现双联动.zip

    2. **事件绑定**:在标题区的每个选项上绑定点击事件,事件处理函数中需要获取被点击标题对应的ScrollView滚动位置,并调用ScrollView的`scrollTo`方法进行滚动。例如: ```html 标题1 ``` ```javascript ...

    ios-scrollView滚动视图.zip

    本资源"ios-scrollView滚动视图.zip"可能包含了关于如何在iOS应用中使用UIScrollView及其相关组件的示例代码和教程。 首先,我们需要理解ScrollView的基本用法。ScrollView本身是一个容器,可以包含多个子视图,如...

    ios-ScrollView滚动.zip

    在这个“ios-ScrollView滚动.zip”压缩包中,可能包含了一个示例项目,展示了如何在iOS应用中实现特卖界面的滚动效果。 ScrollView的基础使用: 1. **初始化**:ScrollView可以通过代码创建,也可以在Storyboard中...

    Android ScrollView向上滑动控件顶部悬浮效果实现

    在Android开发中,ScrollView是一种常用的布局控件,用于容纳单个子视图并允许用户滚动查看超出屏幕的内容。本文将详细讲解如何实现ScrollView向上滑动时,控件顶部悬浮的效果,这种效果通常被称为“头部固定”或...

    安卓标题随ScrollView滚动 颜色渐变 字体变色

    总的来说,实现"安卓标题随ScrollView滚动颜色渐变字体变色"的功能,关键在于监听ScrollView的滚动事件,根据滚动位置计算出颜色渐变和字体变色的比例,然后动态更新标题栏的样式。通过自定义View或使用第三方库,...

    Android双向滚动ScrollView

    此外,为了更好的用户体验,你可能还需要集成Scroller类来实现平滑滚动效果。 总的来说,自定义双向滚动的ScrollView涉及到Android的触摸事件处理机制、测量和布局流程,以及自定义View的开发技巧。通过对这些知识...

    ScrollView循环滚动

    2. **复制内容**:当ScrollView滚动到底部或顶部时,我们需要复制内容到视图的开头或结尾。这样,当用户继续滚动时,可以看到“新的”内容,实际上是重复的原始数据。 3. **平滑过渡**:为了使滚动看起来平滑,我们...

    scrollView自动循环滚动

    当需要实现像轮播图这样的效果,即图片自动循环滚动时,我们可以结合ScrollView和NSTimer来实现这一功能。以下将详细讲解如何在ScrollView上实现图片的自动循环滚动。 首先,我们需要创建一个ScrollView,并设置其...

    Unity嵌套滚动ScrollView.zip

    2. **内容大小**:确保每个ScrollView的内容大小大于其视口大小,这样才能产生滚动效果。 3. **嵌套关系**:子ScrollView需要作为父ScrollView的内容,这样它们才能正确地相互作用。在Unity的Hierarchy面板中,子...

    ScrollView自动滚动

    在实际应用中,我们有时需要实现ScrollView的自动滚动功能,以达到某种动态效果或交互体验。本篇文章将深入探讨如何在Android中实现ScrollView的自动滚动,并结合“ScrollView自动滚动”这一主题,解析相关知识点。 ...

    Unity Super ScrollView 2.4.2 超强功能

    ScrollView通过改变Content的位置来模拟滚动效果,使用户能够在有限的屏幕空间内查看超出界限的内容。 Super ScrollView的亮点在于其无限滚动的能力。在处理大量数据时,传统ScrollView可能会因为一次性加载所有...

    scrollview的回弹效果

    比如`scrollViewDidScroll:`方法,这个方法会在ScrollView滚动时被调用,你可以在这里处理回弹逻辑。 2. **contentInset** 和 **contentOffset**: `contentInset`属性用于设置ScrollView的内容边距,可以用来调整...

    Android ScrollView滚动实现大众点评、网易云音乐评论悬停效果

    Android ScrollView滚动实现大众点评、网易云音乐评论悬停效果 滚动悬停,提高用户转化率 Android Studio源码, 我的博客有相关的源码介绍

    WPF的scrollview滚动条设置及上一页下一页设置

    在本教程中,我们将深入探讨如何设置ScrollViewer的滚动条以及如何实现上一页、下一页的功能。 首先,让我们了解ScrollViewer的基本用法。ScrollViewer是一个可以嵌套其他控件的容器,当其内容超出边界时,会自动...

Global site tag (gtag.js) - Google Analytics