3 Star 3 Fork 1

CHINASOFT2_OHOS / Ohos-InfiniteCards

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README_cn.md 4.99 KB
一键复制 编辑 原始数据 按行查看 历史
xiaoxiangming 提交于 2021-10-18 14:39 . 效果图 展示

InfiniteCards

项目介绍

  • 项目名称:InfiniteCards
  • 所属系列:openharmony的第三方组件适配移植
  • 功能:InfiniteCards是可自定义动效的卡片切换视图
  • 项目移植状态:主功能完成
  • 调用差异:无
  • 开发版本:sdk6,DevEco Studio2.2 Beta1
  • 基线版本:Release 1.0.5

效果演示

效果演示

安装教程

1.在项目根目录下的build.gradle文件中,

allprojects {
   repositories {
       maven {
           url 'https://s01.oss.sonatype.org/content/repositories/releases/'
       }
   }
}

2.在entry模块的build.gradle文件中,

dependencies {
   implementation('com.gitee.chinasoft_ohos:infinite-cards:1.0.6')
   ......  
}

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

使用说明

参数

  • animType : 动效展示类型
    • front : 将点击的卡片切换到第一个
    • switchPosition : 将点击的卡片和第一张卡片互换位置
    • frontToLast : 将第一张卡片移到最后,后面的卡片往前移动一个
  • cardRatio : 卡片宽高比
  • animDuration : 卡片动效时间
  • animAddRemoveDelay : 卡片组切换时,添加与移出时,相邻卡片展示动效的间隔时间
  • animAddRemoveDuration : 卡片组切换时,添加与移出时,卡片动效时间

xml布局

    <com.bakerj.infinitecards.InfiniteCardView
        ohos:id="$+id:view"
        ohos:height="match_parent"
        ohos:width="match_parent"
        app:mCardRatio="1"
        app:animDuration="1000"/>

设置Adapter
直接继承BaseItemProvider

class MyAdapter extends BaseItemProvider{
  ...
}
mAdapter = new MyAdapter(resId);
mCardView.setAdapter(mAdapter);

动效的转换和插值
默认(默认情况下可以不设置,或者设置为各种Default)

mCardView.setAnimInterpolator(new LinearInterpolator());
mCardView.setTransformerToFront(new DefaultTransformerToFront());
mCardView.setTransformerToBack(new DefaultTransformerToBack());
mCardView.setZIndexTransformerToBack(new DefaultZIndexTransformerCommon());

自定义
通过设置转换器与插值器,根据回调中的参数自定义动画效果

mCardView.setTransformerToBack(new AnimationTransformer() {
    @Override
    public void transformAnimation(Component view, float fraction, int cardWidth, int cardHeight, int fromPosition, int toPosition) {
        int positionCount = fromPosition - toPosition;
        float scale = (0.8f - 0.1f * fromPosition) + (0.1f * fraction * positionCount);
        view.setScaleX(scale);
        view.setScaleY(scale);
        if (fraction < 0.5) {
            view.setTranslationX(cardWidth * fraction * 1.5f);
            view.setRotation(-45 * fraction);
        } else {
            view.setTranslationX(cardWidth * 1.5f * (1f - fraction));
            view.setRotation(-45 * (1 - fraction));
        }
    }

    @Override
    public void transformInterpolatedAnimation(Component view, float fraction, int cardWidth, int cardHeight, int fromPosition, int toPosition) {
        int positionCount = fromPosition - toPosition;
        float scale = (0.8f - 0.1f * fromPosition) + (0.1f * fraction * positionCount);
        view.setTranslationY(-cardHeight * (0.8f - scale) * 0.5f - cardWidth * (0.02f *
                fromPosition - 0.02f * fraction * positionCount));
    }
});
mCardView.setZIndexTransformerToBack(new ZIndexTransformer() {
    @Override
    public void transformAnimation(CardItem card, float fraction, int cardWidth, int cardHeight, int fromPosition, int toPosition) {
        if (fraction < 0.5f) {
            card.zIndex = 1f + 0.01f * fromPosition;
        } else {
            card.zIndex = 1f + 0.01f * toPosition;
        }
    }

    @Override
    public void transformInterpolatedAnimation(CardItem card, float fraction, int cardWidth, int cardHeight, int fromPosition, int toPosition) {

    }
});
}

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

当前版本demo功能与原组件基本无差异

版本迭代

  • 1.0.6
  • 0.0.1-SNAPSHOT

版权和许可信息

InfiniteCards is released under the Apache 2.0 license.

Copyright 2017 BakerJ.

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 following link.

     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.
Java
1
https://gitee.com/chinasoft2_ohos/Ohos-InfiniteCards.git
git@gitee.com:chinasoft2_ohos/Ohos-InfiniteCards.git
chinasoft2_ohos
Ohos-InfiniteCards
Ohos-InfiniteCards
master

搜索帮助