介紹
Shimmer是Facebook開源的Java庫,可以使Android中的View控件具有閃光的效果。
使用
下載Shimmer開源庫,并引用到工程中。實際只需要一個ShimmerFrameLayout類,繼承于FrameLayout,將自己的布局控件嵌套在該布局之內以實現閃光的效果。
開始動畫
ShimmerFrameLayout shimmerFrameLayout = (ShimmerFrameLayout) findViewById(R.id.shimmerContent);
shimmerFrameLayout.startShimmerAnimation();
設置動畫間隔
調用ShimmerFrameLayout的setDuration傳入int值設置動畫時間間隔,單位是毫秒。
例:shimmerFrameLayout.setRepeatMode(1000);//間隔1秒
設置動畫重復類型
調用ShimmerFrameLayout的setRepeatMode方法設置動畫的重復模式。
REVERSE:閃光從左到右,再從右到左往復;
RESTART:閃光每次總是從左到右。
例:shimmerFrameLayout.setRepeatMode(ObjectAnimator.REVERSE);
設置閃光傾斜
調用setTilt方法設置光的傾斜角度,參數是float類型,正值:順時針傾斜,負值:逆時針傾斜。
設置閃光角度
調用setAngle方法設置方向,參數只能設置以下四種之一,
ShimmerFrameLayout.MaskAngle.CW_0 :從左到右的方向
ShimmerFrameLayout.MaskAngle.CW_90 :從上到下的方向
ShimmerFrameLayout.MaskAngle.CW_180 :從右到左的方向
ShimmerFrameLayout.MaskAngle.CW_270?:從下到上的方向
設置閃光寬度
調用setDropoff方法設置光的寬度,該值表示的是一個相對的寬度,即表示整個ShimmerFrameLayout寬度的比例。即設置0.5f則表示光的寬度是ShimmerFrameLayout的一半。
設置閃光透明度
setBaseAlpha方法設置沒有光照的地方的透明度。
設置閃光強度
setIntensity設置光的強度。?
設置閃光形狀
setMaskShape方法可以允許設置光的形狀,
線性:ShimmerFrameLayout.MaskShape.LINEAR(默認)
圓形(輻射狀):ShimmerFrameLayout.MaskShape.RADIAL。