无聊练练手之Android自定义动画

xd7251 8年前
   <p>懒得写多少没用的,直接把README贴上来得了。</p>    <h2><strong>Billboard</strong></h2>    <p>Transition the views as billboard.</p>    <p style="text-align:center"><img src="https://simg.open-open.com/show/593df1a548841116a8a1da3095566bf0.gif"></p>    <p style="text-align:center"><img src="https://simg.open-open.com/show/4140c5743f7702bda731073dc2d0602c.gif"></p>    <p style="text-align:center"><img src="https://simg.open-open.com/show/1ed208bc82264af1b83d5bfd12146713.gif"></p>    <h2><strong>How to include</strong></h2>    <pre>  <code class="language-java">dependencies {      compile 'com.zql.android:billboard:1.1'  }</code></pre>    <h2><strong>Usage</strong></h2>    <h2><strong>1. write the code in layout</strong></h2>    <pre>  <code class="language-java"><?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></code></pre>    <h2><strong>2. start Billboard</strong></h2>    <pre>  <code class="language-java">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();</code></pre>    <h2><strong>api</strong></h2>    <h2><strong>xml</strong></h2>    <table>     <thead>      <tr>       <th>property</th>       <th>format</th>       <th>default value</th>       <th>meaning</th>      </tr>     </thead>     <tbody>      <tr>       <td>billboard_columns</td>       <td>integer</td>       <td>10</td>       <td>count that billborad will be cut in horizontal</td>      </tr>      <tr>       <td>billboard_rows</td>       <td>integer</td>       <td>1</td>       <td>count that billborad will be cut in vertical</td>      </tr>      <tr>       <td>billboard_duration</td>       <td>integer</td>       <td>1000</td>       <td>animation duration of one slip</td>      </tr>      <tr>       <td>billboard_delay</td>       <td>integer</td>       <td>300</td>       <td>the time delay of next slip do it animatin</td>      </tr>      <tr>       <td>billboard_refresh</td>       <td>integer</td>       <td>3000</td>       <td>time of two image transition</td>      </tr>      <tr>       <td>billboard_orientation</td>       <td>string</td>       <td>horizontal</td>       <td>orientation of slip's animatin</td>      </tr>     </tbody>    </table>    <h2><strong>java</strong></h2>    <pre>  <code class="language-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)</code></pre>    <h2><strong>version 1.1</strong></h2>    <p>Add a method in BillboardCallback to custom the flip order.</p>    <pre>  <code class="language-java">/**   * 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);</code></pre>    <p>for example:</p>    <p>index * delaymake the order from left to right.</p>    <pre>  <code class="language-java">@Override  public long getDelayFactor(int index, int slipSize,long delay) {      return index * delay;  }</code></pre>    <p> </p>    <p> </p>