安卓环形菜单(处理了菜单键和返回键+加入了动画)

Android动态环形菜单实现指南 在Android开发中,自定义View是实现复杂用户界面功能的关键。环形菜单作为一种独特的UI组件,因其美观和实用的特性,受到了开发者的广泛青睐。本章将介绍如何通过自定义View来实现一个环形菜单,并且解析其背后的原理。动态环形菜单的性能优化和扩展性设计是确保应用长期健康发展的关键。合理地利用分层绘制、异步任务处理、设计模式以及动态加载技术,可以极大地提升应用性能并增强其可扩展性。这些技术的应用,不仅减少了维护成本,还提升了用户体验,使得应用更加灵活和高效。本文还有配套的精品资源,点击获取。 阅读详情

废话不多说,先看效果图:



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/level1"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/level1" >

        <ImageView
            android:id="@+id/icon_home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/icon_home" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/level2"
        android:layout_width="180dp"
        android:layout_height="90dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/level2" >

        <ImageView
            android:id="@+id/icon_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/icon_search" />

        <ImageView
            android:id="@+id/icon_menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:background="@drawable/icon_menu" />

        <ImageView
            android:id="@+id/icon_myyouku"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/icon_myyouku" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/level3"
        android:layout_width="280dp"
        android:layout_height="140dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/level3" >

        <ImageView
            android:id="@+id/channel1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:background="@drawable/channel1" />

        <ImageView
            android:id="@+id/channel2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/channel1"
            android:layout_alignLeft="@id/channel1"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="20dp"
            android:background="@drawable/channel2" />

        <ImageView
            android:id="@+id/channel3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/channel2"
            android:layout_alignLeft="@id/channel2"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="30dp"
            android:background="@drawable/channel3" />

        <ImageView
            android:id="@+id/channel4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:background="@drawable/channel4" />

        <ImageView
            android:id="@+id/channel7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/channel7" />
        
        <ImageView
            android:id="@+id/channel6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/channel7"
            android:layout_alignRight="@id/channel7"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="20dp"
            android:background="@drawable/channel6" />
        
        <ImageView
            android:id="@+id/channel5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/channel6"
            android:layout_alignRight="@id/channel6"
            android:layout_marginBottom="5dp"
            android:layout_marginRight="30dp"
            android:background="@drawable/channel5" />
    </RelativeLayout>

</RelativeLayout>

package com.example.circlemenuofbottom.anim;

import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;

/**
 * @author lzd
 * 
 * QQ : 2622596982
 * 
 * email : anroid_lzd@163.com
 *
 * QQ 交流群 :277599214
 */
public class MyAnimationUtils {

	/**
	 * 出去的动画---顺时针出
	 * 
	 * @param view
	 *            执行动画的对象
	 */
	public static void animaOut(RelativeLayout view) {
		/*
		 * RotateAnimation animation = new RotateAnimation(0, 180,
		 * view.getWidth() / 2, view.getHeight()); animation.setDuration(500);
		 * animation.setFillAfter(true); view.startAnimation(animation);
		 */
		animaOut(view, 0);
	}

	/**
	 * 出去的动画---逆时针进
	 * 
	 * @param view
	 *            执行动画的对象
	 */
	public static void animaIn(RelativeLayout view) {
		/*
		 * // 顺时针进 // RotateAnimation animation = new RotateAnimation(180, //
		 * 360,view.getWidth() / 2, view.getHeight()); // 逆时针进 RotateAnimation
		 * animation = new RotateAnimation(-180, -360, view.getWidth() /
		 * 2,view.getHeight()); animation.setDuration(500);
		 * animation.setFillAfter(true); view.startAnimation(animation);
		 */
		animaIn(view, 0);
	}

	/**
	 * 出去的动画---顺时针出
	 * 
	 * @param view
	 *            执行动画的对象
	 * @param offSetTime
	 *            延时执行的时间
	 */
	public static void animaOut(RelativeLayout view, int offSetTime) {

		RotateAnimation animation = new RotateAnimation(0, 180,
				view.getWidth() / 2, view.getHeight());
		animation.setDuration(500);
		animation.setStartOffset(offSetTime);
		animation.setFillAfter(true);
		view.startAnimation(animation);
	}

	public static void animaIn(RelativeLayout view, int offSetTime) {

		// 顺时针进
		// RotateAnimation animation = new RotateAnimation(180,
		// 360,view.getWidth() / 2, view.getHeight());
		// 逆时针进
		RotateAnimation animation = new RotateAnimation(-180, -360,
				view.getWidth() / 2, view.getHeight());
		animation.setDuration(500);
		animation.setStartOffset(offSetTime);
		animation.setFillAfter(true);
		view.startAnimation(animation);
	}

}


按键的处理思路:

/* 
	 * 监听菜单键,当用户点击菜单键的时候,显示和隐藏一级和二级菜单
	 * 
	 * 监听返回键,再按一次退出程序
	 */
	private long exitTime = 0;
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// 菜单键的处理
		if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_MENU){
			// 如果 一级菜单显示,隐藏 全部
			if(isShowLevel1){
				MyAnimationUtils.animaOut(level);
				isShowLevel1 = false;
				if(isShowLevel2){
					MyAnimationUtils.animaOut(level2,120);
					isShowLevel2 = false;
					if(isShowLevel3){
						MyAnimationUtils.animaOut(level3,120);
						isShowLevel3 = false;
					}
				}
			}else{
				// 如果一级菜单式隐藏的,显示 一,二级菜单
				MyAnimationUtils.animaIn(level);
				MyAnimationUtils.animaIn(level2, 120);
				isShowLevel1 = true;
				isShowLevel2 = true;
			}
		}
		// 返回键
		if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK){
			if(System.currentTimeMillis() - exitTime > 2000){
				Toast.makeText(this, "再按一次返回键退出", Toast.LENGTH_SHORT).show();
				exitTime = System.currentTimeMillis();
			}else{
				finish();
				System.exit(0);
			}
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}



没有什么可以好说的,仔细看看就全懂了,若还有疑问,请联系我 或者 到群里交流。


最后附上下载地址 : http://download.youkuaiyun.com/detail/escdelete/8340545






全方位构建Android环形菜单项目实战 在Android应用开发中,自定义视图绘制是一项重要的技能,它允许开发者创建独特的用户界面元素,以提升用户体验。本章节将详细介绍自定义视图绘制技术的原理、开发流程和高级技巧。创建自定义视图的第一步是继承一个已有的View类。通常情况下,可以选择继承View类本身或者从ViewGroup派生出一个新的布局管理器。// 构造函数// 初始化代码// 属性解析代码@Override// 绘制代码在onDraw方法中,可以使用Canvas对象来进行绘制工作。常用的绘图方法包括。 阅读详情

相关推荐

掌握Android环形菜单特效的设计与实现

自定义View在Android开发中是一个核心概念,它允许开发者创建独特的用户界面组件。与系统提供的标准控件相比,自定义View可以更好地满足特定的应用需求,包括提升用户体验、增加交互效果以及优化布局设计。构建一个自定义View通常包含以下步骤:1. 创建一个新的类,继承自View类或其子类(如TextView、ImageView等)。2. 重写onDraw方法,在其中绘制自定义内容。3. 通过构造函数以及set方法处理参数设置,保持良好的可配置性。

weixin_36474001的博客 1027

android自定义浮动菜单,android 自定义LoopView实现循环菜单

一、可行性分析LoopView是常见的循环View,一般应用于循环展示菜单项目,本次实现的是一组循环菜单,按照垂直方向,实际上,如果把某些变量互换,可以实现轮播图效果。二、效果展示 三、代码实现public class LoopView extends View {private static final int MAX_VISIBLE_COUNT = 5;private TextPaint mT...

weixin_39687468的博客 466

Android环形旋转菜单的实现与应用

在Android中,所有的UI组件都来自于View类。View是所有UI组件的基类,它定义了视图的基本属性和方法。如果你想要创建一个自定义的视图组件,基本上都是通过继承View或者其子类来实现。View: 最基础的视图,如果你只需要一个单纯的显示区域,例如一个简单的图形或者文本,你可以直接继承View类。ViewGroup: 是一个特殊的View,用于包含其他的View或ViewGroup,是布局管理器的基类。ViewGroup可以让你创建复杂的布局结构,比如水平布局、垂直布局等。

weixin_33205138的博客 756

9-Android之设置Menu菜单循环选择-按键控制

9-Android之设置Menu菜单循环选择-按键控制修改ListMenuPresenter修改MenuPopupHelper Android4.4, 展锐平台SC9820W 修改ListMenuPresenter frameworks/base/core/java/com/android/internal/view/menu/ListMenuPresenter.java public MenuView getMenuView(ViewGroup root) { ... mMenuView

陌上 460

Android仿美团菜单(点击可连续切换)

Android仿美团菜单(点击可连续切换)

Android-CircleMenuAndroid源代码

自定义ViewGroup实现的圆形旋转菜单,支持跟随手指旋转以及快速旋转。

Android悬浮缩放菜单的实现

我的视频课程:《FFmpeg打造Android万能音频播放器先看效果图:(文章结尾有Demo下载地址)最近在做一个电商平台的应用,里面有一个效果就是在商品列表上层有一个圆形菜单,在列表滑动时菜单会收缩滑动停止时会展开。刚看到这个效果时感觉不好实现,首先是这个半圆,然后还会收缩变小,但是当我们把这个菜单拆分开来后就很好理解了:1、首先是菜单背景那个圆,其实就是一个实体圆,只是向右偏离了一段距离,所以...

ywl5320的专栏 3160

android圆形旋转菜单,并支持移动换位功能

android圆形旋转菜单,并支持移动换位功能

Android利用Gallery制作无限循环的菜单

Android利用Gallery制作无限循环的菜单 一、创建一个普通的类继承Gallery,目的是为了去掉Gallery滚动的惯性    package cn.com.y2m;    import android.content.Context;    import android.util.AttributeSet;    import android.view.MotionEven

snwrking的专栏 2908

圆环菜单源代码

圆环菜单源代码,只有你想不到的,没有做不到的,是一个很不错的Android源码,有兴趣的伙伴们抽时间可以看一下把

很方便管理的环形菜单

可以旋转的圆形悬浮菜单

android 弹出菜单环形,安卓环形菜单(处理了菜单键和返回键+加入了动画) -电脑资料...

废话不多说,先看效果图:package com.example.circlemenuofbottom.anim;import android.view.animation.RotateAnimation;import android.widget.RelativeLayout;/** * @author lzd * * QQ : 2622596982 * * email :www.2cto.c...

weixin_36418584的博客 158

Android三种菜单实例分析

本文实例讲述了Android的三种菜单。分享给大家供大家参考。具体分析如下: Android的菜单分为三种类型:选项菜单(Option Menu)、上下文菜单(Context Menu)、子菜单(Sub Menu) 一.选项菜单 当用户单击设备上的菜单按钮(Menu),触发事件弹出的菜单就是选项菜单。选项菜单最多只有六个,超过六个第六个就会自动显示 更多 选项来展示显示。 创建方法: 1、覆盖Activity的onCreateOptionsMenu(Menu menu)方法,当我们第一次打开菜单时调用。 2、调用Menu的add()方法添加菜单项(MenuItem),可以调用MenuItem的

Android环形菜单(CircleMenuView )实现

Android环形菜单实现 参考https://github.com/Hitomis/CircleMenu ,在原自定义View中修改了一些代码 效果图: 使用方式: public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private CircleMenuView circleMenu; @Override pro

C_biubiubiu的博客 2354

Snort源代码编译 _ 采坑之旅(for Windows VS2015)

    系统环境:Windows7 sp1 x64     编译环境:VS2015 SP1     Snort版本:2.9.12     daq版本:2.0.6     Snort官网:https://www.snort.org/downloads#snort-downloads 背景     最近需要实现一个类似网络防火墙的产品,主要参考Snort源码,先花了点时间简单读了下网上比较流行的《...

magictong的专栏 8888

SCHUNK SVH五指灵巧手 | 熵洛智能

雄克仿真五指机械手产品系列可以如人手操作那般完美地完成抓取操作。电子装置完全集成于腕关节中,使五指机械手几乎可以完成所有的人体手部动作。凭借带有9个驱动器的运动指骨,机械手可高精度地 执行多种抓取操作。富有弹性的抓取表面确保了对物体的可靠抓取。除了开启抓取和操作任务的全新领域之外,雄克还为在五指机械手的手势基础上进行人与机器人的交流开创了无限可能。编辑切换为居中添加图片注释,不超过 140 字(可选)产品特点:机械手有左手或右手两种版本适合移动应用耗能低,使用 24 V DC 在腕关节处完整集成了控制、调节

ShannonTech的博客 1331

Android-Kotlin实现可滚动的环形菜单

如果想要成为架构师或想突破20~30K薪资范畴,那就不要局限在编码,业务,要会选型、扩展,提升编程思维。此外,良好的职业规划也很重要,学习的习惯很重要,但是最重要的还是要能持之以恒,任何不能坚持落实的计划都是空谈。如果你没有方向,这里给大家分享一套由阿里高级架构师编写的《Android八大模块进阶笔记》,帮大家将杂乱、零散、碎片化的知识进行体系化的整理,让大家系统而高效地掌握Android开发的各个知识点。.........

大模型学习路线 987

从零到一:YOLOv8在边缘设备上的轻量化部署实战

本文详细介绍了YOLOv8在边缘设备上的轻量化部署实战,涵盖模型优化、TensorRT加速、剪枝与知识蒸馏等关键技术。通过工业质检和智能门禁项目案例,展示了如何将YOLOv8高效部署到树莓派、Jetson Nano等资源受限设备,显著提升推理速度和降低内存占用。文章还提供了动态分辨率调整、多模型级联部署等实用技巧,助力开发者实现边缘AI应用的高效落地。

weixin_29040367的博客 379

[android] 优酷环形菜单-旋转动画

获取房子,菜单图标ImageView对象,获取三个圆环RelativeLayout对象 给菜单图标(icon_menu)设置点击事件 定义一个成员变量isLevel3Show来存储第三级菜单是否显示 判断上面的变量,来显示隐藏第三级菜单,定义一个类实现动画效果 切换变量,isLevel3Show=!isLevel3Show 定义一个工具类MyUtils,实现旋转动画...

程序员老狼专注开发aigc或客服系统应用 177

【AIZ智能体】Codex 全能AI助手从部署到使用实战操作详解

Codex 全能AI助手从部署到使用实战操作详解

congge 2982

【DeepSeek-R1 】分词系统架构解析

DeepSeek-R1 分词系统解析 DeepSeek-R1 采用 SentencePiece Unigram 算法,通过统计语言模型实现高效子词分词。其核心优势包括: 算法对比:相比 BPE/WordPiece,Unigram 基于概率模型,支持多语言,自动回退字符级处理。 特性优化:智能空格处理、数字分桶、多语言统一支持,并采用前缀树索引和 SIMD 并行加速,编码速度达 12,458 tok/s。

赶紧的博客 429

android 利用环形菜单制作带数字表盘的时钟

android 利用环形菜单制作带数字表盘的时钟 public class TimerActivity extends AppCompatActivity { private CircleMenuLayoutNoscroll mCircleMenuLayout; private String[] mItemTexts = new String[]{" "," "," ","

liuye066的专栏 1224

5G 模组 FM650 USB模式查询及网络配置

完成以上配置后,5G模组可进行搜网,入网成功后,上位机获取 5G IP。

十年通信老兵的技术修炼之路——从3G到5G,从地面基站到卫星通信。 1322
上一篇: 电子商城开发第一天(基本的分析)
下一篇: android布局采用include 统一管理布局
escdelete
博客等级 码龄14年 37粉丝 69原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值