Android 高仿【优酷】圆盘旋转菜单的实现

2024-03-10 02:58

本文主要是介绍Android 高仿【优酷】圆盘旋转菜单的实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目前,用户对安卓应用程序的UI设计要求越来越高,因此,掌握一些新颖的设计很有必要.

比如菜单,传统的菜单已经不能满足用户的需求. 其中优酷中圆盘旋转菜单的实现就比较优秀,这里我提供下我的思路及实现,仅供参考.


该菜单共分里外三层导航菜单.可以依次从外向里关闭三层菜单,也可以反向打开,并且伴有圆盘旋转的动画效果

首先,看下效果:





以下是具体的代码及解释:

1. 菜单布局文件:

大家看到主要有三个RalativeLayout,就是大家看到的三层,但是关于图片的倾斜 是怎样实现的呢?实际上是个假象,图片是正放的,里面图像是倾斜的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="fill_parent"android:layout_height="fill_parent" ><RelativeLayoutandroid:layout_width="100dip"android:layout_height="50dip"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:background="@drawable/level1" ><ImageButtonandroid:id="@+id/home"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:background="@drawable/icon_home" /></RelativeLayout><RelativeLayoutandroid:layout_width="180dip"android:layout_height="90dip"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:id="@+id/level2"android:background="@drawable/level2" ><ImageButtonandroid:id="@+id/search"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_margin="10dip"android:background="@drawable/icon_search" /><ImageButtonandroid:id="@+id/menu"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_margin="6dip"android:background="@drawable/icon_menu" /><ImageButtonandroid:id="@+id/myyouku"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_margin="10dip"android:background="@drawable/icon_myyouku" /></RelativeLayout><RelativeLayoutandroid:layout_width="280dip"android:layout_height="140dip"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:id="@+id/level3"android:background="@drawable/level3" ><ImageButtonandroid:id="@+id/c1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_marginBottom="6dip"android:layout_marginLeft="12dip"android:background="@drawable/channel1" /><ImageButtonandroid:id="@+id/c2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/c1"android:layout_marginBottom="12dip"android:layout_marginLeft="28dip"android:background="@drawable/channel2" /><ImageButtonandroid:id="@+id/c3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/c2"android:layout_marginBottom="6dip"android:layout_marginLeft="8dip"android:layout_toRightOf="@id/c2"android:background="@drawable/channel3" /><ImageButtonandroid:id="@+id/c4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_margin="6dip"android:background="@drawable/channel4" /><ImageButtonandroid:id="@+id/c5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/c6"android:layout_marginBottom="6dip"android:layout_marginRight="8dip"android:layout_toLeftOf="@+id/c6"android:background="@drawable/channel5" /><ImageButtonandroid:id="@+id/c6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/c7"android:layout_marginBottom="12dip"android:layout_marginRight="28dip"android:layout_alignParentRight="true"android:background="@drawable/channel6" /><ImageButtonandroid:id="@+id/c7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_marginBottom="6dip"android:layout_marginRight="12dip"android:layout_alignParentRight="true"android:background="@drawable/channel7" /></RelativeLayout></RelativeLayout>

2. MainActivity;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RelativeLayout;public class MainActivity extends Activity {private ImageButton home;private ImageButton menu;private RelativeLayout level2;private RelativeLayout level3;private boolean isLevel2Show = true;private boolean isLevel3Show = true;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);home = (ImageButton) findViewById(R.id.home);menu = (ImageButton) findViewById(R.id.menu);level2 = (RelativeLayout) findViewById(R.id.level2);level3 = (RelativeLayout) findViewById(R.id.level3);menu.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {if(isLevel3Show){//隐藏3级导航菜单MyAnimation.startAnimationOUT(level3, 500, 0);}else {//显示3级导航菜单MyAnimation.startAnimationIN(level3, 500);}isLevel3Show = !isLevel3Show;}});home.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {if(!isLevel2Show){//显示2级导航菜单MyAnimation.startAnimationIN(level2, 500);} else {if(isLevel3Show){//隐藏3级导航菜单MyAnimation.startAnimationOUT(level3, 500, 0);//隐藏2级导航菜单MyAnimation.startAnimationOUT(level2, 500, 500);isLevel3Show = !isLevel3Show;}else {//隐藏2级导航菜单MyAnimation.startAnimationOUT(level2, 500, 0);}}isLevel2Show = !isLevel2Show;}});}}

3. 自定义动画类MyAnimation:

import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.RotateAnimation;public class MyAnimation {//入动画public static void startAnimationIN(ViewGroup viewGroup, int duration){for(int i = 0; i < viewGroup.getChildCount(); i++ ){viewGroup.getChildAt(i).setVisibility(View.VISIBLE);//设置显示viewGroup.getChildAt(i).setFocusable(true);//获得焦点viewGroup.getChildAt(i).setClickable(true);//可以点击}Animation animation;/*** 旋转动画* RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue)* fromDegrees 开始旋转角度* toDegrees 旋转到的角度* pivotXType X轴 参照物* pivotXValue x轴 旋转的参考点* pivotYType Y轴 参照物* pivotYValue Y轴 旋转的参考点*/animation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);animation.setFillAfter(true);//停留在动画结束位置animation.setDuration(duration);viewGroup.startAnimation(animation);}//出动画public static void startAnimationOUT(final ViewGroup viewGroup, int duration , int startOffSet){Animation animation;animation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);animation.setFillAfter(true);//停留在动画结束位置animation.setDuration(duration);animation.setStartOffset(startOffSet);animation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationEnd(Animation animation) {for(int i = 0; i < viewGroup.getChildCount(); i++ ){viewGroup.getChildAt(i).setVisibility(View.GONE);//设置显示viewGroup.getChildAt(i).setFocusable(false);//获得焦点viewGroup.getChildAt(i).setClickable(false);//可以点击}}});viewGroup.startAnimation(animation);}
}


这样,一个高仿优酷三级导航圆盘旋转菜单就完成了.,以后完全可以借鉴这些优秀的UI设计,甚至根据新的需求,可以做出更好的UI.


源代码下载地址

http://download.csdn.net/detail/t12x3456/4518220


这篇关于Android 高仿【优酷】圆盘旋转菜单的实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/792804

相关文章

Java中使用Java Mail实现邮件服务功能示例

《Java中使用JavaMail实现邮件服务功能示例》:本文主要介绍Java中使用JavaMail实现邮件服务功能的相关资料,文章还提供了一个发送邮件的示例代码,包括创建参数类、邮件类和执行结... 目录前言一、历史背景二编程、pom依赖三、API说明(一)Session (会话)(二)Message编程客

Java中List转Map的几种具体实现方式和特点

《Java中List转Map的几种具体实现方式和特点》:本文主要介绍几种常用的List转Map的方式,包括使用for循环遍历、Java8StreamAPI、ApacheCommonsCollect... 目录前言1、使用for循环遍历:2、Java8 Stream API:3、Apache Commons

C#提取PDF表单数据的实现流程

《C#提取PDF表单数据的实现流程》PDF表单是一种常见的数据收集工具,广泛应用于调查问卷、业务合同等场景,凭借出色的跨平台兼容性和标准化特点,PDF表单在各行各业中得到了广泛应用,本文将探讨如何使用... 目录引言使用工具C# 提取多个PDF表单域的数据C# 提取特定PDF表单域的数据引言PDF表单是一

使用Python实现高效的端口扫描器

《使用Python实现高效的端口扫描器》在网络安全领域,端口扫描是一项基本而重要的技能,通过端口扫描,可以发现目标主机上开放的服务和端口,这对于安全评估、渗透测试等有着不可忽视的作用,本文将介绍如何使... 目录1. 端口扫描的基本原理2. 使用python实现端口扫描2.1 安装必要的库2.2 编写端口扫

PyCharm接入DeepSeek实现AI编程的操作流程

《PyCharm接入DeepSeek实现AI编程的操作流程》DeepSeek是一家专注于人工智能技术研发的公司,致力于开发高性能、低成本的AI模型,接下来,我们把DeepSeek接入到PyCharm中... 目录引言效果演示创建API key在PyCharm中下载Continue插件配置Continue引言

MySQL分表自动化创建的实现方案

《MySQL分表自动化创建的实现方案》在数据库应用场景中,随着数据量的不断增长,单表存储数据可能会面临性能瓶颈,例如查询、插入、更新等操作的效率会逐渐降低,分表是一种有效的优化策略,它将数据分散存储在... 目录一、项目目的二、实现过程(一)mysql 事件调度器结合存储过程方式1. 开启事件调度器2. 创

使用Python实现操作mongodb详解

《使用Python实现操作mongodb详解》这篇文章主要为大家详细介绍了使用Python实现操作mongodb的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、示例二、常用指令三、遇到的问题一、示例from pymongo import MongoClientf

SQL Server使用SELECT INTO实现表备份的代码示例

《SQLServer使用SELECTINTO实现表备份的代码示例》在数据库管理过程中,有时我们需要对表进行备份,以防数据丢失或修改错误,在SQLServer中,可以使用SELECTINT... 在数据库管理过程中,有时我们需要对表进行备份,以防数据丢失或修改错误。在 SQL Server 中,可以使用 SE

基于Go语言实现一个压测工具

《基于Go语言实现一个压测工具》这篇文章主要为大家详细介绍了基于Go语言实现一个简单的压测工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录整体架构通用数据处理模块Http请求响应数据处理Curl参数解析处理客户端模块Http客户端处理Grpc客户端处理Websocket客户端

Java CompletableFuture如何实现超时功能

《JavaCompletableFuture如何实现超时功能》:本文主要介绍实现超时功能的基本思路以及CompletableFuture(之后简称CF)是如何通过代码实现超时功能的,需要的... 目录基本思路CompletableFuture 的实现1. 基本实现流程2. 静态条件分析3. 内存泄露 bug