Android底部对话框(bottomsheetdialog)如何设置蒙层(scrim)的动画?
创始人
2024-10-07 12:33:55
0
  1. 在布局文件中设置bottom sheet dialog:


    


  1. 创建BottomSheetDialog对象:
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(R.layout.bottom_sheet_dialog);
  1. 获取当前蒙层控件(ScrimView):
View bottomSheet = bottomSheetDialog.getWindow().findViewById(R.id.design_bottom_sheet);
View scrimView = bottomSheet.findViewById(com.google.android.material.R.id.scrim_view);
  1. 设置蒙层动画:
ValueAnimator animator = ObjectAnimator.ofFloat(0.5f, 1.0f);
animator.setDuration(500);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        scrimView.setAlpha((float) animation.getAnimatedValue());
    }
});

bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
        animator.start();
    }
});

bottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        animator.reverse();
    }
});

这里的蒙层动画为透明度渐变动画(从0.5f到1.0f),并将动画的时长设置为500毫秒。最后,在BottomSheetDialog的显示和消失监听器中启动和反转动画。

注意:要使用com.google.android.material.R.id.scrim_view获取蒙层控件ID。

最终效果如下:

相关内容

热门资讯

透视辅助"德州私人局... 透视辅助"德州私人局脚本"详细辅助2025新版技巧(可以买辅助技巧);1.德州私人局脚本 ai辅助创...
透视存在"哈糖大菠萝... 1、透视存在"哈糖大菠萝可以开挂吗"详细辅助力荐教程(买脚本靠谱教程)2、进入游戏-大厅左侧-新手福...
透视计算"智星德州插... 《透视计算"智星德州插件2024最新版"详细辅助新2025版(可以破解游戏教程)》 智星德州插件20...
透视了解"xpoke... 透视了解"xpoker辅助器"详细辅助透牌教程(有机器人教程);1.xpoker辅助器 ai辅助创建...
透视好友房"wepo... 透视好友房"wepoker模拟器哪个"详细辅助2025新版总结(可以开辅助神器);建议优先通过wep...
透视玄学"wpk透视... 透视玄学"wpk透视插件"详细辅助专业教程(买脚本靠谱透明)关于wpk透视插件机制的,其中提到了后台...
透视辅助"aapok... 透视辅助"aapoker怎么选牌"详细辅助插件教程(私人局有透视攻略)关于aapoker怎么选牌机制...
透视实锤"wepok... 透视实锤"wepoker私人局辅助挂"详细辅助透牌教程(可以下载游戏攻略);大神普及一款德州ai内幕...
透视ai"poker... 透视ai"pokermaster脚本"详细辅助软件教程(私人局辅助挂辅助);实战中需综合运用上述技巧...
透视ai"德州局hh... 透视ai"德州局hhpoker"详细辅助靠谱教程(手机版透视脚本神器);《WPK辅助透视》‌:支持手...