项目作者: BakerJQ

项目描述 :
An infinite card switching UI for Android, support custom animation 自定义实现神奇动效的卡片切换视图
高级语言: Java
项目地址: git://github.com/BakerJQ/Android-InfiniteCards.git


InfiniteCards

License

An infinite card switching UI for Android, support custom animation
可自定义动效的卡片切换视图(中文文档

Flutter version

https://github.com/BakerJQ/Flutter-InfiniteCards

Screenshot

Gradle via JitPack

Add it in your root build.gradle at the end of repositories:

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Add the dependency

  1. dependencies {
  2. implementation 'com.github.BakerJQ:Android-InfiniteCards:1.0.5'
  3. }

Attrs

  • animType : animation type
    • front : move the selected card to first
    • switchPosition : move the selected card to first, and the first card to the selected position
    • frontToLast : move the first card to last position
  • cardRatio : ratio of the card
  • animDuration : duration of each card’s animation
  • animAddRemoveDelay : delay of animation of add and remove between each card
  • animAddRemoveDuration : duration of add and remove each card’s animation

How to use

layout in xml

  1. <com.bakerj.infinitecards.InfiniteCardView
  2. android:id="@+id/view"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. infiniteCard:animDuration="1000"
  6. infiniteCard:cardRatio="1"></com.bakerj.infinitecards.InfiniteCardView>

Set Adapter

Just extends the BaseAdapter

  1. class MyAdapter extends BaseAdapter{
  2. ...
  3. }
  4. mAdapter = new MyAdapter(resId);
  5. mCardView.setAdapter(mAdapter);

Animation transformers and interpolators

Default

If you just use all default animations, just do nothing.

  1. mCardView.setAnimInterpolator(new LinearInterpolator());
  2. mCardView.setTransformerToFront(new DefaultTransformerToFront());
  3. mCardView.setTransformerToBack(new DefaultTransformerToBack());
  4. mCardView.setZIndexTransformerToBack(new DefaultZIndexTransformerCommon());

Customisation

  1. mCardView.setTransformerToBack(new AnimationTransformer() {
  2. @Override
  3. public void transformAnimation(View view, float fraction, int cardWidth, int cardHeight, int fromPosition, int toPosition) {
  4. int positionCount = fromPosition - toPosition;
  5. float scale = (0.8f - 0.1f * fromPosition) + (0.1f * fraction * positionCount);
  6. ViewHelper.setScaleX(view, scale);
  7. ViewHelper.setScaleY(view, scale);
  8. if (fraction < 0.5) {
  9. ViewCompat.setRotationX(view, 180 * fraction);
  10. } else {
  11. ViewCompat.setRotationX(view, 180 * (1 - fraction));
  12. }
  13. }
  14. @Override
  15. public void transformInterpolatedAnimation(View view, float fraction, int cardWidth, int cardHeight, int fromPosition, int toPosition) {
  16. int positionCount = fromPosition - toPosition;
  17. float scale = (0.8f - 0.1f * fromPosition) + (0.1f * fraction * positionCount);
  18. ViewHelper.setTranslationY(view, -cardHeight * (0.8f - scale) * 0.5f - cardWidth * (0.02f *
  19. fromPosition - 0.02f * fraction * positionCount));
  20. }
  21. });
  22. mCardView.setZIndexTransformerToBack(new ZIndexTransformer() {
  23. @Override
  24. public void transformAnimation(CardItem card, float fraction, int cardWidth, int cardHeight, int fromPosition, int toPosition) {
  25. if (fraction < 0.4f) {
  26. card.zIndex = 1f + 0.01f * fromPosition;
  27. } else {
  28. card.zIndex = 1f + 0.01f * toPosition;
  29. }
  30. }
  31. @Override
  32. public void transformInterpolatedAnimation(CardItem card, float fraction, int cardWidth, int cardHeight, int fromPosition, int toPosition) {
  33. }
  34. });

License

InfiniteCards is released under the Apache 2.0 license.

  1. Copyright 2017 BakerJ.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at following link.
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.