FaceBook微光閃爍---第三方開源--shimmer-android,facebookandroidsdk
Android上的微光閃爍shimmer效果,實現的手段不少,其中比較好的是facebook做的開源庫:shimmer-android,其在github上的項目首頁是:https://github.com/facebook/shimmer-android 另外一個連結:http://facebook.github.io/shimmer-android/ 其實指向的項目都是一個項目內容。
要使用facebook的Android Shimmer微光閃爍,需要先到其首頁下載jar包,下載後直接放到自己Eclipse的項目libs裡面。然後在布局檔案中寫一個com.facebook.shimmer.ShimmerFrameLayout布局,包裹自己的view.
比如一個TextView:
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 > 6 7 <com.facebook.shimmer.ShimmerFrameLayout 8 android:id="@+id/shimmer_view_container" 9 android:layout_width="wrap_content"10 android:layout_height="wrap_content"11 android:layout_centerInParent="true" >12 13 <TextView14 android:layout_width="wrap_content"15 android:layout_height="wrap_content"16 android:background="#ffc400"17 android:padding="10dip"18 android:text="android"19 android:textColor="#eeeeee"20 android:textSize="20sp" />21 </com.facebook.shimmer.ShimmerFrameLayout>22 23 </RelativeLayout>
1 package com.zzw.shimmer; 2 3 import com.facebook.shimmer.ShimmerFrameLayout; 4 5 import android.app.Activity; 6 import android.os.Bundle; 7 8 public class MainActivity extends Activity { 9 10 @Override11 protected void onCreate(Bundle savedInstanceState) {12 super.onCreate(savedInstanceState);13 setContentView(R.layout.activity_main);14 15 ShimmerFrameLayout container = (ShimmerFrameLayout) findViewById(R.id.shimmer_view_container);16 17 //執行的時間長度18 container.setDuration(2500);19 20 //開始執行效果21 container.startShimmerAnimation();22 }23 }