目前,用户对安卓应用程序的UI设计要求越来越高,因此,掌握一些新颖的设计很有必要,比如菜单,传统的菜单已经不能满足用户的需求。其中圆盘旋转菜单的实现就比较好,该菜单共分里外三层导航菜单.可以依次从外向里关闭三层菜单,也可以反向打开,并且伴有圆盘旋转的动画效果,首先,看下效果:
源码下载:http://download.csdn.net/detail/weidi1989/4588807

以下是具体的代码及解释:
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" >
<RelativeLayout
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/level1" >
<ImageButton
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/icon_home" />
</RelativeLayout>
<RelativeLayout
android:layout_width="180dip"
android:layout_height="90dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/level2"
android:background="@drawable/level2" >
<ImageButton
android: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" />
<ImageButton
android: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" />
<ImageButton
android: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>
<RelativeLayout
android:layout_width="280dip"
android:layout_height="140dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/level3"
android:background="@drawable/level3" >
<ImageButton
android: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" />
<ImageButton
android: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" />
<ImageButton
android: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" />
<ImageButton
android: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" />
<ImageButton
android: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" />
<ImageButton
android: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" />
<ImageButton
android: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:
package cn.oce.youku;
import cn.itcast.youku.R;
import android.os.Bundle;
import android.app.Activity;
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;
@Override
public 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() {
@Override
public void onClick(View v) {
if(isLevel3Show){
//隐藏3级导航菜单
MyAnimation.startAnimationOUT(level3, 500, 0);
}else {
//显示3级导航菜单
MyAnimation.startAnimationIN(level3, 500);
}
isLevel3Show = !isLevel3Show;
}
});
home.setOnClickListener(new OnClickListener() {
@Override
public 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:
package cn.oce.youku;
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() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public 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。
分享到:
相关推荐
本教程将带你了解如何在Android Studio中实现一个带有动画效果的可弹出并收回的按钮菜单。这个功能不仅能够增加应用的交互性,还能为用户提供一种新颖的互动方式。 首先,我们需要设置一个基础的布局,通常是一个...
- **TranslationAnimation**:Android提供的基础动画类型之一,可以用于改变View的位置。在侧滑菜单中,我们可以通过TranslationAnimation使菜单视图从屏幕边缘滑出或滑入。 - **ObjectAnimator**:Android 3.0...
"Android游戏开发之游戏主菜单与进度条加载源码"这个主题涵盖了这两个关键领域,为开发者提供了一手的学习资料。下面将详细介绍这两个方面的知识点。 1. 游戏主菜单: - 主菜单界面设计:游戏的主菜单通常是玩家...
在Android平台上开发游戏时,创建吸引人的主菜单和有效的进度条加载是提升用户体验的关键环节。本文将深入探讨如何实现这两个功能。 首先,我们来看“Android 绘制游戏主菜单”。在Android应用中,主菜单通常作为...
在Android平台上实现“仿iPhone主题之主菜单”的设计,主要涉及到UI界面的定制、控件的使用以及动画效果的实现。下面将详细讲解这个主题下的关键知识点。 首先,我们需要了解Android与iOS在用户界面设计上的差异。...
在Android游戏开发中,主菜单和进度条加载是至关重要的组成部分。它们不仅为用户提供界面交互,还确保游戏的流畅启动和加载过程。本资源提供的是关于Android游戏中实现这两个功能的源代码,帮助开发者深入理解其背后...
Facebook是最早采用这种设计的App之一,因此在Android开发中,"仿Facebook侧拉菜单"成为了这种功能的代名词。 实现这种侧拉菜单功能,开发者通常会使用Android官方提供的`android.support.v4.widget.DrawerLayout`...
系统Launcher主菜单是Android操作系统中的一个重要组成部分,它负责呈现用户界面,使用户能够启动和管理应用程序。这个模块不仅包括了启动应用的图标和列表,还包括了各种系统设置、搜索功能和快捷方式。深入理解并...
Android中侧滑菜单效果实现(主界面和菜单界面实现平移、缩放、滚动动画),详细了解请移步:http://blog.csdn.net/zxc514257857/article/details/72602778
Android的动画系统允许开发者创建各种动态效果,TranslateAnimation就是其中之一,它用于改变view的位置。在PATH菜单效果中,子菜单项会从主菜单按钮的某个方向(如下方或右侧)滑出。通过设置TranslateAnimation的...
在Android应用开发中,主界面通常需要一个底部菜单(Bottom Navigation)来提供多个主要功能间的快速切换,提高用户体验。这个DEMO就是关于如何在Android应用中实现底部菜单的一个实例。我们将探讨以下几个关键知识...
本文将深入探讨如何实现一个仿网易新闻安卓端菜单栏动画,这是Android动画系列的第二部分。通过这个实战案例,开发者可以了解到如何利用Android的动画API来创建复杂的交互式效果,增强应用的视觉吸引力。 首先,...
这种菜单通常悬浮在主内容之上,用户可以通过滑动手势来展示或隐藏,增强了界面的动态感和互动性。本教程将深入探讨如何实现这样一个功能,我们将基于提供的"ScrollMenuDemo"项目进行分析。 首先,滑动隐藏菜单的...
总的来说,创建一个具有动画效果的按钮菜单是提升Android应用用户体验的重要手段。通过熟练掌握布局设计、事件监听和动画API,开发者可以创造出更具吸引力的交互界面。而"MenuAnimation-master"的示例代码正是实践这...
本项目"Android应用源码之菜单动画(类似QQ空间)Demo"旨在展示如何实现一个与QQ空间相似的菜单动画效果。通过分析和学习这个源码,开发者可以掌握在Android平台上创建动态、交互丰富的菜单界面的技术。 首先,我们要...
这样的菜单通常包含主菜单、子菜单以及可能的孙子菜单,允许用户逐级深入探索内容。 首先,我们需要理解Android菜单的基本概念。在Android中,菜单通常通过`Menu`类来实现,它可以在Activity的`onCreateOptionsMenu...
DrawerLayout,鸿洋前辈的博客中其实写的已经很不错了,但是在ViewHelper的动画设置上,鸿洋前辈并未有过多的描述,对笔者此类没接触过nineoldandroids动画的新手来讲真的有点余言未尽的感觉,于是笔者下载了前辈的...