美文网首页
鸿蒙学习-ScrollView

鸿蒙学习-ScrollView

作者: 学渣中的战斗渣 | 来源:发表于2021-04-08 10:09 被阅读0次

ScrollView是一种带滚动功能的组件,它采用滑动的方式在有限的区域内显示更多的内容。

ScrollView的自有XML属性

match_viewport:是否拉伸匹配,boolean类型,对应方法setMatchViewportEnabled();

rebound_effect:回弹效果,boolean类型,对应方法setReboundEffect();

常用方法

doFling(int velocityX, int velocityY)

doFlingX(int velocityX)

doFlingY(int velocityY)

设置X轴和Y轴滚动的初始速度,单位(px)

fluentScrollBy(int dx, int dy)

fluentScrollByX(int dx)

fluentScrollByY(int dy)

根据像素数平滑滚动到指定位置,单位(px)

fluentScrollTo(int x, int y)

fluentScrollXTo(int x)

fluentScrollYTo(int y)

根据指定坐标平滑滚动到指定位置,单位(px)

setReboundEffect(boolean enabled)

设置是否启用回弹效果,默认false

setReboundEffectParams(int overscrollPercent, float overscrollRate, int remainVisiblePercent)

setReboundEffectParams(ReboundEffectParams reboundEffectParams)

setOverscrollPercent(int overscrollPercent)

setOverscrollRate(float overscrollRate)

setRemainVisiblePercent(int remainVisiblePercent)

配置回弹效果

overscrollPercent:过度滚动百分比,默认值40

overscrollRate:过度滚动率,默认值0.6

remainVisiblePercent:应保持可见内容的最小百分比,默认值20

竖向滑动子控件高设置为match_content,宽设置为match_parent

横向滑动子控件宽设置为match_content,高设置为match_parent

横竖都滑动子控件宽高设置为match_content

示例代码

<ScrollView

    ohos:id="$+id:sv"

    ohos:height="match_parent"

    ohos:width="match_parent"

    ohos:rebound_effect="true">

<!--内部可以有多个控件,最好只设置一个,实际滑动的是子控件,ScrollView自身没有设置布局方向的属性,所以需要在其子布局中设置。-->

<DirectionalLayout

        ohos:id="$+id:layout"

        ohos:height="match_content"

        ohos:width="match_parent"

        ohos:orientation="vertical">

<Image

    ohos:height="match_content"

    ohos:width="300vp"

    ohos:image_src="$media:plant"

    ohos:top_margin="16vp"/>

<!-- 放置任意需要展示的组件 -->

</DirectionalLayout>

</ScrollView>

效果图:

回弹效果图:

相关文章

  • 鸿蒙学习-ScrollView

    ScrollView是一种带滚动功能的组件,它采用滑动的方式在有限的区域内显示更多的内容。 ScrollView的...

  • React Native08 - ScrollView、Scro

    前言 本篇我们的要学习的内容如下: 组件ScrollView 使用ScrollView实现轮播图 一、组件Scro...

  • 鸿蒙学习-权限

    本文章基于SDK(API Version 5)进行开发 权限分类 权限的grantMode是system_gran...

  • 鸿蒙学习-ListContainer

    ListContainer是用来呈现连续、多行数据的组件,包含一系列相同类型的列表项。 自有XML属性 rebou...

  • 鸿蒙学习-PageFlipper

    PageFlipper:翻页器,当PageFlipper有两个或多个子组件时,切换期间设置动画时,PageFlip...

  • 鸿蒙学习-ToastDialog

    ToastDialog:在窗口上方提供toast对话框,以通知操作的简单反馈。Toast对话框不可单击,它将自动消...

  • 鸿蒙学习-Checkbox

    Checkbox实现选中和取消选中的功能。从代码上看和RadioButton没有区别,但是由于SDK并没有开源,没...

  • Day 4 - ScrollView,视频采集

    不完整效果图如下 今天了解学习ScrollView 1、搭建UI 这里我们使用XIB拖入ScrollView,添加...

  • 鸿蒙系统的手机📱.. ‖ Updating

    文/ 煜兮 【学习笔记/原创】 {192/365} 华为已经官宣了正式启用鸿蒙系统,搭载华为鸿蒙系统的荣耀智慧...

  • RunLoop学习小记

    RunLoop学习小记 先描述一个场景,scrollView上有一个定时器,但是每当我们滑动scrollView时...

网友评论

      本文标题:鸿蒙学习-ScrollView

      本文链接:https://www.haomeiwen.com/subject/pdumkltx.html