1 Star 1 Fork 0

CHINASOFT_OHOS / RollViewPager

Create your Gitee Account
Explore and code with more than 8 million developers,Free private repositories !:)
Sign up
Clone or Download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

RollViewPager

项目介绍

  • 项目名称:RollViewPager
  • 所属系列:openharmony第三方组件适配移植
  • 功能:轮播图自定义组件
  • 项目移植状态:主功能完成
  • 调用差异:有
    原项目中暂停和播放的三个方法,ohos替换成了一个方法
  • 开发版本:sdk6,DevEco Studio2.2 Beta1
  • 基线版本: 1.4.6

效果演示

example

安装教程

1.在moudle级别下的build.gradle文件中添加依赖,在dependencies标签中增加对libs目录下jar包的引用

// 添加maven仓库
repositories {
   maven {
        url 'https://s01.oss.sonatype.org/content/repositories/release/'
   }
}
// 添加依赖库
dependencies {
   implementation 'com.gitee.chinasoft_ohos:rollviewpager:1.0.1'   
}

在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下

使用说明

  • xml属性
 <com.jude.rollviewpager.RollPagerView
      ohos:height="180vp"
      ohos:width="match_parent"
    /> 
  • Java 调用示例 提供一个适配器PageSliderAdapter继承PageSliderProvider类,在该类中实现createPageInContainer方法可自行定义自己需要轮播的界面,
 @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
     
        ViewHolder viewHolder;
        Component component = null;

        if (component == null) {
            component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_pager_item, null, false);
            if (!(component instanceof ComponentContainer)) {
                return "";
            }
            componentContainer.addComponent(component);
            viewHolder = new ViewHolder();
            viewHolder.image = (Image) componentContainer.findComponentById(ResourceTable.Id_image_pager);
            component.setTag(this);
        } else {
            viewHolder = (ViewHolder) component.getTag();
        }
        viewHolder.image.setPixelMap(pages.get(i));
        viewHolder.image.setScaleMode(Image.ScaleMode.STRETCH);

        return componentContainer;
    }
  • 实现适配器和加入轮播图片的方法
 /**
     * 设置适配器和轮播的图片
     *
     * @param pageSliderAdapter 适配器
     * @param page 带图片的list集合
     */
    public void setadapter(PageSliderAdapter pageSliderAdapter, ArrayList<Integer> page) {
        pageSlider.setProvider(pageSliderAdapter);
        this.pages = page;
    }
  • 暂停和播放功能,默认是播放,调用这个方法,此方法会自己判断播放和暂停
 private boolean isStartEnd = true; // true,轮播图默认是播放
 /**
     * 暂停或者播放.true播放,flase是暂停,默认播放
     */
    public void setStartEnd() {
        if (isStartEnd) {
            this.isStartEnd = false;
        } else {
            this.isStartEnd = true;
        }
    }
  • 加入图片到list集合中,并且new一个适配器加入到组件中
 ArrayList<Integer> page = new ArrayList<>();
        page.add(ResourceTable.Media_img1);
        page.add(ResourceTable.Media_img2);
        page.add(ResourceTable.Media_img3);
        page.add(ResourceTable.Media_img4);
        page.add(ResourceTable.Media_img5);
        PageSliderAdapter bannerAdapter1 = new PageSliderAdapter(page, getContext());
        rollPagerView.setadapter(bannerAdapter1, page);
  • ClickedListener,item的点击事件
  rollPagerView.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
               //这里写自己的逻辑代码
            }
        });

测试信息

CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与ohos原组件基本无差异

版本迭代

  • 1.0.1

版权和许可信息

Copyright 2015 Jude

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at'


http://www.apache.org/licenses/LICENSE-2.0


'Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Repository Comments ( 0 )

Sign in to post a comment

About

自动轮播的 ViewPager expand collapse
Java
Cancel

Releases

No release

RollViewPager

Contributors

All

Activities

Load More
can not load any more
Java
1
https://git.oschina.net/chinasoft_ohos/RollViewPager.git
git@git.oschina.net:chinasoft_ohos/RollViewPager.git
chinasoft_ohos
RollViewPager
RollViewPager
master

Search