本项目是基于开源项目ContinuousScrollableImageView进行鸿蒙化的移植和开发的,可以通过项目标签以及github地址( https://github.com/Cutta/ContinuousScrollableImageView )追踪到原安卓项目版本
项目名称:开源连续滚动图像控件
所属系列:鸿蒙的第三方组件适配移植
功能:可以显示具有连续滚动效果的图像,支持设置图像源、缩放类型、持续时间和方向。
项目移植状态:90%
调用差异:现在只能通过java代码来实现,具体的调用方式见下方实例。
开发版本:sdk5,DevEco Studio2.1 beta3
项目发起作者:刘磊
原项目Doc地址:https://github.com/Cutta/ContinuousScrollableImageView
编程语言:Java
下载加载动画jar包continuousscrollableimageview.jar。 启动 DevEco Studio,将下载的jar包,导入工程目录“entry->libs”下。 在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下jar包的引用,随后执行gradle sync。
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
……
}
布局文件定义,提供控件:ContinuousScrollableImageView 引入方法:import com.cunoraz.continuousscrollable.ContinuousScrollableImageView; ContinuousScrollableImageView布局、属性设置,这里使用了两种方式进行布局,其中飞机图像和云图像使用的是正常方式进行布局和属性设置,山图像使用的是Builder方式进行布局和属性设置:
//飞机图像布局
LayoutConfig planeConfig=new LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,0,LayoutConfig.UNSPECIFIED_ALIGNMENT,1);
ContinuousScrollableImageView plane=new ContinuousScrollableImageView(this);
plane.setLayoutConfig(planeConfig);
plane.setDirection(ContinuousScrollableImageView.RIGHT);
plane.setDuration(2500);
plane.setScaleType(ContinuousScrollableImageView.CENTER_INSIDE);
plane.setResourceId(ResourceTable.Media_plane);
layout.addComponent(plane);
//云图像布局
LayoutConfig cloudConfig=new LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,0,LayoutConfig.UNSPECIFIED_ALIGNMENT,1);
ContinuousScrollableImageView cloud=new ContinuousScrollableImageView(this);
cloud.setLayoutConfig(cloudConfig);
cloud.setDirection(ContinuousScrollableImageView.LEFT);
cloud.setDuration(4000);
cloud.setResourceId(ResourceTable.Media_cloud);
layout.addComponent(cloud);
//山图像Builder方式布局
LayoutConfig mountainConfig=new LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,0,LayoutConfig.UNSPECIFIED_ALIGNMENT,1);
ContinuousScrollableImageView mountain=new ContinuousScrollableImageView.Builder(this.getAbility())
.setDirection(ContinuousScrollableImageView.LEFT)
.setDuration(6000)
.setResourceId(ResourceTable.Media_mountain)
.build();
mountain.setLayoutConfig(mountainConfig);
layout.addComponent(mountain);
可以使用通过setDirection来设置方向,setDuration设置时间间隔,setScaleType设置缩放类型,setResourceId设置图像源。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。