Android自定义动画之广告牌翻动效果

懒得写多少没用的,直接把README贴上来得了。
这是源码github地址

若你对代码实现有啥疑惑欢迎前来咨询。

Billboard

Transition the views as billboard.



See it on Youtube

How to include

dependencies {
    compile 'com.zql.android:billboard:1.1'
}

Usage

1. write the code in layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.zql.android.bambooslipdemo.MainActivity">

    <com.zql.android.bambooslip.Billboard
        android:id="@+id/billboard"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:billboard_columns="40"
        app:billboard_rows="1"
        app:billboard_delay="120"
        app:billboard_duration="1200"
        app:billboard_refresh="500"
        app:billboard_orientation="horizontal"
        android:background="@android:color/black"/>

</RelativeLayout>

2. start Billboard

billboard = (Billboard) findViewById(R.id.billboard);
billboard.setCallback(new Billboard.BillboardCallback() {
    @Override
    public Bitmap getBitmap(int count) {
        if(count%5 == 0){
            return BitmapFactory.decodeResource(getResources(),R.mipmap.b1);
        }
        if(count%5 == 1){
            return BitmapFactory.decodeResource(getResources(),R.mipmap.b2);
        }
        if(count%5== 2){
            return BitmapFactory.decodeResource(getResources(),R.mipmap.b3);
        }
        if(count%5 == 3){
            return BitmapFactory.decodeResource(getResources(),R.mipmap.b4);
        }
        if(count%5 == 4){
            return BitmapFactory.decodeResource(getResources(),R.mipmap.b5);
        }
        return null;
    }
    @Override
    public long getDelayFactor(int index, int slipSize,long delay) {
        return index * delay;
    }
});
billboard.go();

api

xml

property format default value meaning
billboard_columns integer 10 count that billborad will be cut in horizontal
billboard_rows integer 1 count that billborad will be cut in vertical
billboard_duration integer 1000 animation duration of one slip
billboard_delay integer 300 the time delay of next slip do it animatin
billboard_refresh integer 3000 time of two image transition
billboard_orientation string horizontal orientation of slip's animatin

java

    /**
     * set the callback
     * @param callback {@link BillboardCallback}
     */
    Billboard.setCallback(BillboardCallback callback)

    /**
     * {@link Billboard}'s callback
     */
    public interface BillboardCallback {
        /**
         * get a bitmap to show
         * @param count {0,1,2,3,4,5,6,7,8, ... ,Integer.MAX_VALUE}
         * @return
         */
        Bitmap getBitmap(int count);
    /**
         * custom the delay time of every slip
         * @param index slip index
         * @param delay the time you define in layout xml
         * @param slipSize the size of slip
         * @return delayfactor
         */
        long getDelayFactor(int index,int slipSize,long delay);
    }

    /**
     * start flip
     */
    Billboard.go()

    /**
     * end flip
     */
    Billboard.endFlip()

    /**
     * set timeInterpolator of flip animation
     * @param timeInterpolator
     */
    Billboard.setTimeInterpolator(TimeInterpolator timeInterpolator)

version 1.1

Add a method in BillboardCallback to custom the flip order.

/**
 * custom the delay time of every slip
* @param index slip index
* @param delay the time you define in layout xml
* @param slipSize the size of slip
* @return delayfactor
*/
long getDelayFactor(int index,int slipSize,long delay);

for example:

index * delay make the order from left to right.

@Override
public long getDelayFactor(int index, int slipSize,long delay) {
    return index * delay;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 11,316评论 0 23
  • 文/鸿运 袅袅炊烟抹过窗 文墨拙笔淡淡香 瑟瑟枫红销魂处 一帘秋思雁声长
    HONGYUNDANGTOU阅读 483评论 5 12
  • 《同读一本书》2016-9-7-105 正文: 目标是重要的。而实现目标的方法也同样重要。这听上去非常简单,可正像...
    台东万达DDM一店张春燕阅读 255评论 1 0
  • 在某个日落的黄昏下 站在家里的阳台上 我偶尔还会看见那么一幅画面 有几头老牛从冬茅草里 摇摇摆摆钻了出来 老人走得...
    逗霸君阅读 702评论 7 11
  • 高三补习班的日子真的很枯燥,每天除了上课就是有一大堆作业要做,除了考试就是考试,每天都在紧张忙碌中度过,班里从第一...
    妮诗兰阅读 296评论 0 0

友情链接更多精彩内容