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

相关文章

MyBatis流式查询两种实现方式

《MyBatis流式查询两种实现方式》本文详解MyBatis流式查询,通过ResultHandler和Cursor实现边读边处理,避免内存溢出,ResultHandler逐条回调,Cursor支持迭代... 目录MyBATis 流式查询详解:ResultHandler 与 Cursor1. 什么是流式查询?

Android 缓存日志Logcat导出与分析最佳实践

《Android缓存日志Logcat导出与分析最佳实践》本文全面介绍AndroidLogcat缓存日志的导出与分析方法,涵盖按进程、缓冲区类型及日志级别过滤,自动化工具使用,常见问题解决方案和最佳实... 目录android 缓存日志(Logcat)导出与分析全攻略为什么要导出缓存日志?按需过滤导出1. 按

Springboot项目登录校验功能实现

《Springboot项目登录校验功能实现》本文介绍了Web登录校验的重要性,对比了Cookie、Session和JWT三种会话技术,分析其优缺点,并讲解了过滤器与拦截器的统一拦截方案,推荐使用JWT... 目录引言一、登录校验的基本概念二、HTTP协议的无状态性三、会话跟android踪技术1. Cook

C++归并排序代码实现示例代码

《C++归并排序代码实现示例代码》归并排序将待排序数组分成两个子数组,分别对这两个子数组进行排序,然后将排序好的子数组合并,得到排序后的数组,:本文主要介绍C++归并排序代码实现的相关资料,需要的... 目录1 算法核心思想2 代码实现3 算法时间复杂度1 算法核心思想归并排序是一种高效的排序方式,需要用

mybatis用拦截器实现字段加解密全过程

《mybatis用拦截器实现字段加解密全过程》本文通过自定义注解和MyBatis拦截器实现敏感信息加密,处理Parameter和ResultSet,确保数据库存储安全且查询结果解密可用... 目录前言拦截器的使用总结前言根据公司业务需要,灵活对客户敏感信息进行加解密,这里采用myBATis拦截器进行简单实

java实现多数据源切换方式

《java实现多数据源切换方式》本文介绍实现多数据源切换的四步方法:导入依赖、配置文件、启动类注解、使用@DS标记mapper和服务层,通过注解实现数据源动态切换,适用于实际开发中的多数据源场景... 目录一、导入依赖二、配置文件三、在启动类上配置四、在需要切换数据源的类上、方法上使用@DS注解结论一、导入

SQLServer中生成雪花ID(Snowflake ID)的实现方法

《SQLServer中生成雪花ID(SnowflakeID)的实现方法》:本文主要介绍在SQLServer中生成雪花ID(SnowflakeID)的实现方法,文中通过示例代码介绍的非常详细,... 目录前言认识雪花ID雪花ID的核心特点雪花ID的结构(64位)雪花ID的优势雪花ID的局限性雪花ID的应用场景

Linux升级或者切换python版本实现方式

《Linux升级或者切换python版本实现方式》本文介绍在Ubuntu/Debian系统升级Python至3.11或更高版本的方法,通过查看版本列表并选择新版本进行全局修改,需注意自动与手动模式的选... 目录升级系统python版本 (适用于全局修改)对于Ubuntu/Debian系统安装后,验证Pyt

Python实现开根号的五种方式

《Python实现开根号的五种方式》在日常数据处理、数学计算甚至算法题中,开根号是一个高频操作,但你知道吗?Python中实现开根号的方式远不止一种!本文总结了5种常用方法,感兴趣的小伙伴跟着小编一起... 目录一、为什么需要多种开根号方式?二、5种开根号方式详解方法1:数学库 math.sqrt() ——

nginx配置错误日志的实现步骤

《nginx配置错误日志的实现步骤》配置nginx代理过程中,如果出现错误,需要看日志,可以把nginx日志配置出来,以便快速定位日志问题,下面就来介绍一下nginx配置错误日志的实现步骤,感兴趣的可... 目录前言nginx配置错误日志总结前言在配置nginx代理过程中,如果出现错误,需要看日志,可以把