博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android编程 扇形展开的悬浮菜单按钮CircularFloatingActionMenu实例
阅读量:3949 次
发布时间:2019-05-24

本文共 4584 字,大约阅读时间需要 15 分钟。

               

Android编程:扇形展开的悬浮菜单按钮CircularFloatingActionMenu实例

本文博客链接:,作者:jdh,转载请注明.

环境:

主机:

开发环境: Studio 2.2 Preview 3

说明:

用第三方库CircularFloatingActionMenu实现悬浮按钮扇形展开

效果图:

源码:

private void initFloatingActionsMenu(View view) {        // 添加 右下角的白色+号按钮        final ImageView fabIcon = new ImageView(getContext());        fabIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_fab, null));        final FloatingActionButton fabButton = new FloatingActionButton.Builder(getActivity())                .setContentView(fabIcon)                .setPosition(FloatingActionButton.POSITION_BOTTOM_LEFT)                .build();        SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(getActivity());        ImageView imageViewQuit = new ImageView(getContext());        ImageView imageViewTool = new ImageView(getContext());        ImageView imageViewPalette = new ImageView(getContext());        ImageView imageViewCamera = new ImageView(getContext());        imageViewQuit.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_end_black_48dp, null));        imageViewTool.setImageDrawable(getResources().getDrawable(R.drawable.ic_settings_applications_black_48dp, null));        imageViewPalette.setImageDrawable(getResources().getDrawable(R.drawable.ic_color_lens_black_48dp, null));        imageViewCamera.setImageDrawable(getResources().getDrawable(R.drawable.ic_camera_alt_black_48dp, null));        SubActionButton buttonQuit = rLSubBuilder.setContentView(imageViewQuit).build();        SubActionButton buttonPalette = rLSubBuilder.setContentView(imageViewPalette).build();        SubActionButton buttonTool = rLSubBuilder.setContentView(imageViewTool).build();        SubActionButton buttonCamera = rLSubBuilder.setContentView(imageViewCamera).build();        // Build the menu with default options: light theme, 90 degrees, 72dp        // radius.        // Set 4 default SubActionButtons        // FloatingActionMenu通过attachTo(fabButton)附着到FloatingActionButton        final FloatingActionMenu buttonToolMenu = new FloatingActionMenu.Builder(getActivity())                .addSubActionView(buttonPalette)                .addSubActionView(buttonCamera)                .addSubActionView(buttonTool)                .addSubActionView(buttonQuit)                .setStartAngle(0)                .setEndAngle(-90)                .attachTo(fabButton)                .build();        // Listen menu open and close events to animate the button content view        buttonToolMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {            @Override            public void onMenuOpened(FloatingActionMenu menu) {                // 增加按钮中的+号图标顺时针旋转45度                // Rotate the icon of fabButton 45 degrees clockwise                fabIcon.setRotation(0);                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 45);                ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIcon, pvhR);                animation.start();            }            @Override            public void onMenuClosed(FloatingActionMenu menu) {                // 增加按钮中的+号图标逆时针旋转45度                // Rotate the icon of fabButton 45 degrees                // counter-clockwise                fabIcon.setRotation(45);                PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 0);                ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIcon, pvhR);                animation.start();            }        });        RxView.clicks(buttonQuit)                .throttleFirst(1, TimeUnit.SECONDS)                .compose(this.bindUntilEvent(FragmentEvent.DESTROY))                .subscribe(v -> {                    Voip.getInstance().hangUpCall(callId);                    finishActivity();                });        RxView.clicks(buttonPalette)                .throttleFirst(1, TimeUnit.SECONDS)                .compose(this.bindUntilEvent(FragmentEvent.DESTROY))                .subscribe(v -> {                    buttonToolMenu.close(true);//                    buttonToolMenu.collapse();                    dialogPalette.show();                });        RxView.clicks(buttonCamera)                .throttleFirst(1, TimeUnit.SECONDS)                .compose(this.bindUntilEvent(FragmentEvent.DESTROY))                .subscribe(v -> {                    buttonToolMenu.close(true);//                    buttonToolMenu.collapse();                    dialogSelectImage.show();                });    }

参考链接:

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!

你可能感兴趣的文章
Supporting Different Densities 支持各种屏幕密度
查看>>
Implementing Adaptative UI Flows 实施自适应用户界面流程
查看>>
Crossfading Two Views 淡入淡出的两种观点
查看>>
Using ViewPager for Screen Slides 使用屏幕幻灯片ViewPager
查看>>
Displaying Card Flip Animations 显示卡片翻转动画
查看>>
Zooming a View 缩放视图
查看>>
Animating Layout Changes 动画布局的更改
查看>>
Controlling Your App’s Volume and Playback 控制应用程序的音量和播放
查看>>
Managing Audio Focus 管理音频焦点
查看>>
Dealing with Audio Output Hardware 处理音频输出硬件设备
查看>>
Monitoring the Battery Level and Charging State 监测电池电量和充电状态
查看>>
Determining and Monitoring the Docking State and Type 判断并监测设备的停驻状态与类型
查看>>
Determining and Monitoring the Connectivity Status 根据网络连接状况去省电
查看>>
Manipulating Broadcast Receivers On Demand 按需操控广播接收
查看>>
Creating a View Class 创建一个视图类
查看>>
Custom Drawing 自定义绘制
查看>>
Making the View Interactive 视图互动
查看>>
Optimizing the View 优化视图
查看>>
Setting Up the Search Interface 设置搜索界面
查看>>
Storing and Searching for Data 数据存储和搜索
查看>>