介绍
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。