懒得写多少没用的,直接把README贴上来得了。
这是源码github地址
若你对代码实现有啥疑惑欢迎前来咨询。
Billboard
Transition the views as billboard.
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;
}