HarmonyOS ScrollView 使用
ScrollView 介绍
ScrollView是一种带滚动功能的组件,它采用滑动的方式在有限的区域内显示更多的内容。
本来很简单的不打算记录,但是各种坑啊,哎.现在学习大致了解就行,
ScrollView的自有XML属性
1 match_viewport 是否拉伸匹配 默认为false
2 rebound_effect 回弹效果 默认为false
下面吐槽下这2个属性
match_viewport 这个属性感觉有bug ,说下感受呢,当ScrollView 不设置属性时候,无论是文字还是图片当宽度大于屏幕的宽度的时候,设置ScrollView为水平滚动的方向,但是这个时候左右也是可以滑动的如果不理解看下面的效果图
这个时候设置match_viewport 为true 就不存这个问题,设置之后图片子组件填充满ScrollView
但是却怎么也不滑动了,希望后面能修复吧,或者就是自己其他的地方没有设置
2 rebound_effect 这个属性设置回弹,设置之后有回弹但是不能滚动了,这里就上传gif图片了
录制了2个现在csdn有限制大小总是上传不了.
ScrollView 使用注意
ScrollView 属性里面字内容不能有多个否则也滑动不了,所以可以在字内容外写一个布局包含
要滑动的内容一般都是使用DirectionalLayout 相当于线性布局,通过设置orientation来控制是
垂直滑动还是水平滑动
垂直滑动
<?xml version="1.0" encoding="utf-8"?>
<ScrollViewxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:id="$+id:scroll"><DirectionalLayoutohos:height="match_content"ohos:width="match_content"ohos:orientation="vertical"><Imageohos:width="match_parent"ohos:height="200vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/></DirectionalLayout>
</ScrollView>
水平滑动
<?xml version="1.0" encoding="utf-8"?>
<ScrollViewxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:id="$+id:scroll"><DirectionalLayoutohos:height="match_content"ohos:width="match_content"ohos:orientation="horizontal"><Imageohos:width="match_parent"ohos:height="200vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/><Imageohos:width="match_parent"ohos:height="200vp"ohos:top_margin="16vp"ohos:scale_mode="clip_center"ohos:image_src="$media:three"/></DirectionalLayout>
</ScrollView>
ScrollView的速度、滚动、回弹等常用接口
方法 |
作用 |
---|---|
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 |
官方参考地址
HarmonyOS ScrollView 使用相关推荐
- HarmonyOS ScrollView 不滑动的问题
HarmonyOS ScrollView 本来就是看看文档,然后想着写一下看看, 结果泪崩了,弄了2个小时啊,阿西吧, 就是不滑动,最后睡觉前把宽高的属性设置了以下 就好了 不滑动的原因就是 把加载字 ...
- HarmonyOS之常用组件ScrollView的功能和使用
一.ScrollView 功能 ScrollView 是一种带滚动功能的组件,它采用滑动的方式在有限的区域内显示更多的内容. 二.支持的 XML 属性 ScrollView 的共有 XML 属性继承自 ...
- HarmonyOS之常用组件TabList与Tab的功能和使用
一.什么是 Tablist 与 Tab ? Tablist 可以实现多个页签栏的切换,Tab 为某个页签. 子页签通常放在内容区上方,展示不同的分类. 页签名称应该简洁明了,清晰描述分类的内容. 二. ...
- HarmonyOS之组件布局的创建和使用
一.组件与布局 HarmonyOS 提供了Ability 和 AbilitySlice 两个基础类,一个有界面的 Ability 可以由一个或多个 AbilitySlice 构成,AbilitySli ...
- HarmonyOS之应用工程结构与设备模板
一.HarmonyOS APP 工程结构 ① HarmonyOS 应用的逻辑结构 HarmonyOS 应用发布形态为 APP Pack(Application Package,简称APP),它是由一个 ...
- 《 HarmonyOS实战—可搭载在车机、大屏、智能手表、平板电脑、手机的计算器它来啦!》
[本文正在参与"有奖征文 | HarmonyOS征文大赛"活动] 目录 布局的实现 Java代码逻辑 GIF演示实现效果 布局的实现 Layout_ability_main.xml ...
- HarmonyOS开发详解(四)——鸿蒙Page Ability功能及UI界面开发详解
HarmonyOS里面的界面通过Page Ability和Java UI一起来实现:讲述Page Ability就离不开Ability.在HarmonyOS里面把各种具备的能力进行抽象,叫做Abili ...
- HarmonyOS技术特性
HarmonyOS技术特性 硬件互助,资源共享 多种设备之间能够实现硬件互助.资源共享,依赖的关键技术包括分布式软总线.分布式设备虚拟化.分布式数据管理.分布式任务调度等. 分布式软总线 分布式软总线 ...
- HarmonyOS系统概述
HarmonyOS系统概述 系统定位 HarmonyOS是一款"面向未来".面向全场景(移动办公.运动健康.社交通信.媒体娱乐等)的分布式操作系统.在传统的单设备系统能力的基础上, ...
最新文章
- 爬虫神器xpath的用法(一)
- 第十一周项目实践2 用邻接表存储的图来实现基本应用
- 【译】Activitys, Threads和 内存泄露
- Wi-Fi Expert专业无线网测试软件
- TensorFlow神经网络(九)VGG net论文阅读笔记
- Mysql 主从复制简易操作指南
- ogg格式文件怎么转mp3格式
- SteamVR 错误代码 108 / 203 / 208 / 301 / 306 / 308 / 400 / 405 排解方法
- Android ndk开发C调用C++
- WinTel联盟发展史
- Priceline拥有五个子品牌分别是:Booking.com、Priceline.com、Agoda、Kayak 以及Rentalcars
- 鸿蒙系统是电脑还是手机,鸿蒙系统什么时候能用在电脑上,华为鸿蒙系统什么时候能用...
- YOLOv4原文翻译 - v4它终于来了!
- Spark与大数据处理技术实践
- VSPD软件发送与串口线发送区别
- 民宿OTA运营有哪些指标数据最重要
- 盘符没有显示,磁盘管理器提示磁盘没有初始化(已解决)
- 公司电脑怎样能做到统一管理?
- opencv--读取摄像头识别人脸并跟踪
- 英特尔 82801DB ICH4 - AC'97 Audio 控制器 [A-1] 声卡驱动安装!
热门文章
- 2022-2028年中国铅锌精矿粉行业市场研究及前瞻分析报告
- 【Sql Server】DateBase-视频总结
- 【VB】学生信息管理系统5——数据库代码
- TensorRT简介
- com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4e47db1f -- Acquisition Attempt Failed!!!
- 自动生成低精度深度学习算子
- 端云一体人工智能开发平台整体架构
- 用matlab怎么画视电阻率拟断面图,在MATLAB平台上实现可控源音频大地电磁反演数据三维可视化显示...
- php dedecms 记录访问者ip,dedecms实现显示访问者ip地址的方法
- 微信小程序扫描二维码