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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容

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