Android底部工作表弹跳动画
创始人
2024-10-07 12:33:56
0
  1. 创建布局文件:在底部工作表布局文件中添加一个RecyclerView或ListView。
  2. 在Activity/Fragment中,设置底部工作表的弹跳动画效果:
    BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
    RecyclerView recyclerView = findViewById(R.id.recycler_view);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);
    MyAdapter myAdapter = new MyAdapter(dataList);
    recyclerView.setAdapter(myAdapter);
    bottomSheetDialog.setContentView(recyclerView);
    try {
        Field behaviorField = bottomSheetDialog.getClass().getDeclaredField("behavior");
        if (behaviorField != null) {
            behaviorField.setAccessible(true);
            Object behavior = behaviorField.get(bottomSheetDialog);
            if (behavior instanceof BottomSheetBehavior) {
                BottomSheetBehavior bottomSheetBehavior = (BottomSheetBehavior) behavior;
                bottomSheetBehavior.setBottomSheetCallback(new BottomSheetCallback() {
                    @Override
                    public void onStateChanged(@NonNull View bottomSheet, int newState) {
                        if (newState == BottomSheetBehavior.STATE_EXPANDED) {
                            animateIn(mainLayout);
                        } else if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                            animateOut(mainLayout);
                            bottomSheetDialog.dismiss();
                        }
                    }
                    
                    @Override
                    public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                        // Set the translationX/Y of mainLayout here to achieve the bounce animation effect
                    }
                });
            }
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
  1. 为了实现弹跳动画效果,通过修改布局中主要布局的translationX/Y值来使其在弹跳动画的过程中改变其位置。具体可以在onSlide回调方法中实现:
    private void animateIn(View view) {
        Animation animation = new TranslateAnimation(0, 0, view.getHeight(), 0);
        animation.setDuration(300);
        view.startAnimation(animation);
    }

    private void animateOut(View view) {
        Animation animation = new TranslateAnimation(0, 0, 0

相关内容

热门资讯

透视总结"wepok... 透视总结"wepoker免费脚本咨询"详细辅助存在挂教程(脚本下载技巧);wepoker免费脚本咨询...
透视辅助"cloud... 透视辅助"cloudpoker外挂"详细辅助透明教程(透视脚本网页技巧);《WPK辅助透视》‌:支持...
透视玄学"werpl... 透视玄学"werplan外挂"详细辅助揭秘攻略(透视app下载透视)1、不需要AI权限,帮助你快速的...
透视好友"佛手大菠萝... 1、透视好友"佛手大菠萝辅助"详细辅助教你攻略(手机版透视脚本技巧)2、进入游戏-大厅左侧-新手福利...
透视安装"德州辅助工... 1、透视安装"德州辅助工具到底怎么样"详细辅助大神讲解(免费钻石方法)2、进入游戏-大厅左侧-新手福...
透视透视"pokem... 透视透视"pokemmo辅助器脚本下载"详细辅助切实教程(网页版透视方法教程);1分钟了解详细教程(...
透视计算"wepok... 透视计算"wepoker有辅助工具吗"详细辅助教你攻略(外挂辅助);1分钟了解详细教程(微信 136...
透视黑科技"wepo... 透视黑科技"wepoker可以透视码"详细辅助技巧教程(可以开透视技巧);亲真的是有正版授权,小编(...
透视游戏"wepok... 1、透视游戏"wepoker黑侠辅助器"详细辅助玩家教你(辅助软件价格攻略);详细教程。2、wepo...
透视挂透视"aa p... 透视挂透视"aa poker辅助包"详细辅助透明挂教程(究竟有透视神器);建议优先通过aa poke...