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

相关文章

Spring Boot整合Redis注解实现增删改查功能(Redis注解使用)

《SpringBoot整合Redis注解实现增删改查功能(Redis注解使用)》文章介绍了如何使用SpringBoot整合Redis注解实现增删改查功能,包括配置、实体类、Repository、Se... 目录配置Redis连接定义实体类创建Repository接口增删改查操作示例插入数据查询数据删除数据更

Java Lettuce 客户端入门到生产的实现步骤

《JavaLettuce客户端入门到生产的实现步骤》本文主要介绍了JavaLettuce客户端入门到生产的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目录1 安装依赖MavenGradle2 最小化连接示例3 核心特性速览4 生产环境配置建议5 常见问题

linux ssh如何实现增加访问端口

《linuxssh如何实现增加访问端口》Linux中SSH默认使用22端口,为了增强安全性或满足特定需求,可以通过修改SSH配置来增加或更改SSH访问端口,具体步骤包括修改SSH配置文件、增加或修改... 目录1. 修改 SSH 配置文件2. 增加或修改端口3. 保存并退出编辑器4. 更新防火墙规则使用uf

Java 的ArrayList集合底层实现与最佳实践

《Java的ArrayList集合底层实现与最佳实践》本文主要介绍了Java的ArrayList集合类的核心概念、底层实现、关键成员变量、初始化机制、容量演变、扩容机制、性能分析、核心方法源码解析、... 目录1. 核心概念与底层实现1.1 ArrayList 的本质1.1.1 底层数据结构JDK 1.7

C++中unordered_set哈希集合的实现

《C++中unordered_set哈希集合的实现》std::unordered_set是C++标准库中的无序关联容器,基于哈希表实现,具有元素唯一性和无序性特点,本文就来详细的介绍一下unorder... 目录一、概述二、头文件与命名空间三、常用方法与示例1. 构造与析构2. 迭代器与遍历3. 容量相关4

C++中悬垂引用(Dangling Reference) 的实现

《C++中悬垂引用(DanglingReference)的实现》C++中的悬垂引用指引用绑定的对象被销毁后引用仍存在的情况,会导致访问无效内存,下面就来详细的介绍一下产生的原因以及如何避免,感兴趣... 目录悬垂引用的产生原因1. 引用绑定到局部变量,变量超出作用域后销毁2. 引用绑定到动态分配的对象,对象

SpringBoot基于注解实现数据库字段回填的完整方案

《SpringBoot基于注解实现数据库字段回填的完整方案》这篇文章主要为大家详细介绍了SpringBoot如何基于注解实现数据库字段回填的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以了解... 目录数据库表pom.XMLRelationFieldRelationFieldMapping基础的一些代

Java HashMap的底层实现原理深度解析

《JavaHashMap的底层实现原理深度解析》HashMap基于数组+链表+红黑树结构,通过哈希算法和扩容机制优化性能,负载因子与树化阈值平衡效率,是Java开发必备的高效数据结构,本文给大家介绍... 目录一、概述:HashMap的宏观结构二、核心数据结构解析1. 数组(桶数组)2. 链表节点(Node

Java AOP面向切面编程的概念和实现方式

《JavaAOP面向切面编程的概念和实现方式》AOP是面向切面编程,通过动态代理将横切关注点(如日志、事务)与核心业务逻辑分离,提升代码复用性和可维护性,本文给大家介绍JavaAOP面向切面编程的概... 目录一、AOP 是什么?二、AOP 的核心概念与实现方式核心概念实现方式三、Spring AOP 的关

Python实现字典转字符串的五种方法

《Python实现字典转字符串的五种方法》本文介绍了在Python中如何将字典数据结构转换为字符串格式的多种方法,首先可以通过内置的str()函数进行简单转换;其次利用ison.dumps()函数能够... 目录1、使用json模块的dumps方法:2、使用str方法:3、使用循环和字符串拼接:4、使用字符