再也别说你不会 ShimmerFrameLayout ,真的超级容易 【开发必备】

1、shimmer-android是Facebook出品的给任意视图添加微光效果的第三方库。

2、配置

dependencies {
   implementation 'com.facebook.shimmer:shimmer:0.4.0'
 }  

3、基本使用

    <com.facebook.shimmer.ShimmerFrameLayout
        android:id="@+id/shimmer_view_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <!--我们希望起微光效果的视图-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="我的微信公众号:自学者" />
            
    </com.facebook.shimmer.ShimmerFrameLayout>  

4、在Java文件中开启微光动画

ShimmerFrameLayout container = (ShimmerFrameLayout) findViewById(R.id.shimmer_view_container);
        //开启微光动画
        container.startShimmerAnimation();  
        //container.startShimmer() 上面执行的开始动画可能失效,可以使用标记的这个

5、方法参数

setAutoStart():设置是否自动启动微光动画
setBaseAlpha:设置基视图的背景颜色
setDuration():从一个布局到另一个布局亮点需要时间。
setRepeatCount():设置当前动画重复的次数
setRepeatDelay():延迟多长时间重复当前动画
setRepeatMode():设置动画重复的模式
setMaskShape():设置当前高亮面具的形状
setAngle():设置当前高亮面具的角度

6、常用属性

设置shimmer动画的时间间隔 :ShimmerFrameLayout.setDuration(int); //传入一个int值来对动画的时间间隔设置,单位是毫秒

设置shimmer动画重复类型:shimmerFrameLayout.setRepeatMode(ObjectAnimator.REVERSE);
REVERSE表示:闪光从左到右,之后在从右到左这样往复;
RESTART表示:闪光每次总是从左到右。

设置shimmer闪光的倾斜角度:调用setTilt方法设置光的倾斜角度,传入参数是float类型,表示倾斜的角度,正值表示顺时针倾斜,负值表示逆时针倾斜。
1、ShimmerFrameLayout.MaskAngle.CW_0 表示从左到右的方向
2、ShimmerFrameLayout.MaskAngle.CW_90 表示从上到下的方向
3、ShimmerFrameLayout.MaskAngle.CW_180 表示从右到左的方向
4、ShimmerFrameLayout.MaskAngle.CW_270 表示从下到上的方向

设置shimmer闪光的宽度:调用setDropoff方法设置光的宽度,该值表示的是一个相对的宽度,即表示整个ShimmerFrameLayout宽度的比例。即若设置该值为0.5f则表示光的宽度是ShimmerFrameLayout的一半。

设置shimmer闪光的透明度:
1、setBaseAlpha方法允许我们设置没有光照的地方的透明度。
2、setIntensity设置光的强度,根据测试来看,应该是被光照的边缘部分的透明度。

设置shimmer闪光的形状: 
1、setMaskShape方法可以允许我们设置光的形状,目前可以设置为线性
2、ShimmerFrameLayout.MaskShape.LINEAR(默认),
3、圆形或者叫辐射状ShimmerFrameLayout.MaskShape.RADIAL。

7、GitHub:

https://github.com/facebook/shimmer-android

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Android上为您的布局和RecyclerView实现面纱骨架和闪烁效果,可以通过以下步骤实现: 1. 首先,您需要使用一个库来实现面纱骨架和闪烁效果。推荐使用Shimmer-android库,它是一个轻量级的库,易于使用,并且具有良好的性能。 2. 在您的build.gradle文件中添加以下依赖项: ``` dependencies { implementation 'com.facebook.shimmer:shimmer:0.5.0' } ``` 3. 在您的布局文件中添加ShimmerFrameLayout视图: ``` <com.facebook.shimmer.ShimmerFrameLayout android:id="@+id/shimmer_view_container" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- Your layout here --> </com.facebook.shimmer.ShimmerFrameLayout> ``` 4. 在您的代码中,您需要初始化ShimmerFrameLayout并开始/停止动画: ``` ShimmerFrameLayout shimmerFrameLayout = findViewById(R.id.shimmer_view_container); shimmerFrameLayout.startShimmer(); // 开始动画 shimmerFrameLayout.stopShimmer(); // 停止动画 ``` 5. 如果您想在RecyclerView中实现面纱骨架和闪烁效果,则可以在RecyclerView.Adapter中重写onCreateViewHolder方法,并在其中使用ShimmerFrameLayout: ``` @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.my_item_layout, parent, false); final ShimmerFrameLayout shimmerFrameLayout = itemView.findViewById(R.id.shimmer_view_container); shimmerFrameLayout.startShimmer(); return new ViewHolder(itemView); } ``` 6. 当您的数据加载完成时,您需要停止ShimmerFrameLayout动画并显示真实数据: ``` @Override public void onBindViewHolder(ViewHolder holder, int position) { // Bind data to views holder.textView.setText(mDataList.get(position).getText()); // Stop shimmer animation and show real data holder.shimmerFrameLayout.stopShimmer(); holder.shimmerFrameLayout.setVisibility(View.GONE); holder.textView.setVisibility(View.VISIBLE); } ``` 这样,您就可以在Android上为您的布局和RecyclerView实现面纱骨架和闪烁效果了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

其子昱舟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值