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

分类:android 1393人阅读 评论(9) 收藏 举报

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

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

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

首先,看下效果:

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

1. 菜单布局文件:

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

[java] view plain copy
  1. <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent">
  5. <RelativeLayout
  6. android:layout_width="100dip"
  7. android:layout_height="50dip"
  8. android:layout_alignParentBottom="true"
  9. android:layout_centerHorizontal="true"
  10. android:background="@drawable/level1">
  11. <ImageButton
  12. android:id="@+id/home"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:layout_centerInParent="true"
  16. android:background="@drawable/icon_home"/>
  17. </RelativeLayout>
  18. <RelativeLayout
  19. android:layout_width="180dip"
  20. android:layout_height="90dip"
  21. android:layout_alignParentBottom="true"
  22. android:layout_centerHorizontal="true"
  23. android:id="@+id/level2"
  24. android:background="@drawable/level2">
  25. <ImageButton
  26. android:id="@+id/search"
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:layout_alignParentBottom="true"
  30. android:layout_margin="10dip"
  31. android:background="@drawable/icon_search"/>
  32. <ImageButton
  33. android:id="@+id/menu"
  34. android:layout_width="wrap_content"
  35. android:layout_height="wrap_content"
  36. android:layout_centerHorizontal="true"
  37. android:layout_margin="6dip"
  38. android:background="@drawable/icon_menu"/>
  39. <ImageButton
  40. android:id="@+id/myyouku"
  41. android:layout_width="wrap_content"
  42. android:layout_height="wrap_content"
  43. android:layout_alignParentBottom="true"
  44. android:layout_alignParentRight="true"
  45. android:layout_margin="10dip"
  46. android:background="@drawable/icon_myyouku"/>
  47. </RelativeLayout>
  48. <RelativeLayout
  49. android:layout_width="280dip"
  50. android:layout_height="140dip"
  51. android:layout_alignParentBottom="true"
  52. android:layout_centerHorizontal="true"
  53. android:id="@+id/level3"
  54. android:background="@drawable/level3">
  55. <ImageButton
  56. android:id="@+id/c1"
  57. android:layout_width="wrap_content"
  58. android:layout_height="wrap_content"
  59. android:layout_alignParentBottom="true"
  60. android:layout_marginBottom="6dip"
  61. android:layout_marginLeft="12dip"
  62. android:background="@drawable/channel1"/>
  63. <ImageButton
  64. android:id="@+id/c2"
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:layout_above="@id/c1"
  68. android:layout_marginBottom="12dip"
  69. android:layout_marginLeft="28dip"
  70. android:background="@drawable/channel2"/>
  71. <ImageButton
  72. android:id="@+id/c3"
  73. android:layout_width="wrap_content"
  74. android:layout_height="wrap_content"
  75. android:layout_above="@id/c2"
  76. android:layout_marginBottom="6dip"
  77. android:layout_marginLeft="8dip"
  78. android:layout_toRightOf="@id/c2"
  79. android:background="@drawable/channel3"/>
  80. <ImageButton
  81. android:id="@+id/c4"
  82. android:layout_width="wrap_content"
  83. android:layout_height="wrap_content"
  84. android:layout_centerHorizontal="true"
  85. android:layout_margin="6dip"
  86. android:background="@drawable/channel4"/>
  87. <ImageButton
  88. android:id="@+id/c5"
  89. android:layout_width="wrap_content"
  90. android:layout_height="wrap_content"
  91. android:layout_above="@+id/c6"
  92. android:layout_marginBottom="6dip"
  93. android:layout_marginRight="8dip"
  94. android:layout_toLeftOf="@+id/c6"
  95. android:background="@drawable/channel5"/>
  96. <ImageButton
  97. android:id="@+id/c6"
  98. android:layout_width="wrap_content"
  99. android:layout_height="wrap_content"
  100. android:layout_above="@+id/c7"
  101. android:layout_marginBottom="12dip"
  102. android:layout_marginRight="28dip"
  103. android:layout_alignParentRight="true"
  104. android:background="@drawable/channel6"/>
  105. <ImageButton
  106. android:id="@+id/c7"
  107. android:layout_width="wrap_content"
  108. android:layout_height="wrap_content"
  109. android:layout_alignParentBottom="true"
  110. android:layout_marginBottom="6dip"
  111. android:layout_marginRight="12dip"
  112. android:layout_alignParentRight="true"
  113. android:background="@drawable/channel7"/>
  114. </RelativeLayout>
  115. </RelativeLayout>

2. MainActivity;

[java] view plain copy
  1. importandroid.os.Bundle;
  2. importandroid.app.Activity;
  3. importandroid.view.Menu;
  4. importandroid.view.View;
  5. importandroid.view.View.OnClickListener;
  6. importandroid.widget.ImageButton;
  7. importandroid.widget.RelativeLayout;
  8. publicclassMainActivityextendsActivity{
  9. privateImageButtonhome;
  10. privateImageButtonmenu;
  11. privateRelativeLayoutlevel2;
  12. privateRelativeLayoutlevel3;
  13. privatebooleanisLevel2Show=true;
  14. privatebooleanisLevel3Show=true;
  15. @Override
  16. publicvoidonCreate(BundlesavedInstanceState){
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. home=(ImageButton)findViewById(R.id.home);
  20. menu=(ImageButton)findViewById(R.id.menu);
  21. level2=(RelativeLayout)findViewById(R.id.level2);
  22. level3=(RelativeLayout)findViewById(R.id.level3);
  23. menu.setOnClickListener(newOnClickListener(){
  24. @Override
  25. publicvoidonClick(Viewv){
  26. if(isLevel3Show){
  27. //隐藏3级导航菜单
  28. MyAnimation.startAnimationOUT(level3,500,0);
  29. }else{
  30. //显示3级导航菜单
  31. MyAnimation.startAnimationIN(level3,500);
  32. }
  33. isLevel3Show=!isLevel3Show;
  34. }
  35. });
  36. home.setOnClickListener(newOnClickListener(){
  37. @Override
  38. publicvoidonClick(Viewv){
  39. if(!isLevel2Show){
  40. //显示2级导航菜单
  41. MyAnimation.startAnimationIN(level2,500);
  42. }else{
  43. if(isLevel3Show){
  44. //隐藏3级导航菜单
  45. MyAnimation.startAnimationOUT(level3,500,0);
  46. //隐藏2级导航菜单
  47. MyAnimation.startAnimationOUT(level2,500,500);
  48. isLevel3Show=!isLevel3Show;
  49. }
  50. else{
  51. //隐藏2级导航菜单
  52. MyAnimation.startAnimationOUT(level2,500,0);
  53. }
  54. }
  55. isLevel2Show=!isLevel2Show;
  56. }
  57. });
  58. }
  59. }

3. 自定义动画类MyAnimation:

[java] view plain copy
  1. importandroid.view.View;
  2. importandroid.view.ViewGroup;
  3. importandroid.view.animation.Animation;
  4. importandroid.view.animation.Animation.AnimationListener;
  5. importandroid.view.animation.RotateAnimation;
  6. publicclassMyAnimation{
  7. //入动画
  8. publicstaticvoidstartAnimationIN(ViewGroupviewGroup,intduration){
  9. for(inti=0;i<viewGroup.getChildCount();i++){
  10. viewGroup.getChildAt(i).setVisibility(View.VISIBLE);//设置显示
  11. viewGroup.getChildAt(i).setFocusable(true);//获得焦点
  12. viewGroup.getChildAt(i).setClickable(true);//可以点击
  13. }
  14. Animationanimation;
  15. /**
  16. *旋转动画
  17. *RotateAnimation(fromDegrees,toDegrees,pivotXType,pivotXValue,pivotYType,pivotYValue)
  18. *fromDegrees开始旋转角度
  19. *toDegrees旋转到的角度
  20. *pivotXTypeX轴参照物
  21. *pivotXValuex轴旋转的参考点
  22. *pivotYTypeY轴参照物
  23. *pivotYValueY轴旋转的参考点
  24. */
  25. animation=newRotateAnimation(-180,0,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,1.0f);
  26. animation.setFillAfter(true);//停留在动画结束位置
  27. animation.setDuration(duration);
  28. viewGroup.startAnimation(animation);
  29. }
  30. //出动画
  31. publicstaticvoidstartAnimationOUT(finalViewGroupviewGroup,intduration,intstartOffSet){
  32. Animationanimation;
  33. animation=newRotateAnimation(0,-180,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,1.0f);
  34. animation.setFillAfter(true);//停留在动画结束位置
  35. animation.setDuration(duration);
  36. animation.setStartOffset(startOffSet);
  37. animation.setAnimationListener(newAnimationListener(){
  38. @Override
  39. publicvoidonAnimationStart(Animationanimation){
  40. //TODOAuto-generatedmethodstub
  41. }
  42. @Override
  43. publicvoidonAnimationRepeat(Animationanimation){
  44. //TODOAuto-generatedmethodstub
  45. }
  46. @Override
  47. publicvoidonAnimationEnd(Animationanimation){
  48. for(inti=0;i<viewGroup.getChildCount();i++){
  49. viewGroup.getChildAt(i).setVisibility(View.GONE);//设置显示
  50. viewGroup.getChildAt(i).setFocusable(false);//获得焦点
  51. viewGroup.getChildAt(i).setClickable(false);//可以点击
  52. }
  53. }
  54. });
  55. viewGroup.startAnimation(animation);
  56. }
  57. }


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

源代码下载地址

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

更多相关文章

  1. 改用 Android(安卓)之后 II
  2. android:同时弹出顶部和底部菜单的做法
  3. Android之framework修改底部导航栏NavigationBar动态显示和隐藏
  4. Android菜单系统介绍
  5. Android(安卓)解决android4.0系统中菜单(Menu)添加Icon无效问题
  6. 【Android(安卓)开发】:UI控件之 ImageView 实现图片旋转和缩放功
  7. Android仿人人客户端(v5.7.1)——有关滑动式左侧菜单实现过程中网
  8. android动画的透明度渐变、旋转动画、缩放动画、评议动画
  9. Android(安卓)实现底部导航切换的几种方式

随机推荐

  1. android 记事本
  2. Android Stdio实现简单计算器
  3. Android实现录制视频
  4. Android 使用内容解析者往短信数据库里插
  5. android工程没有gen路径
  6. 移植Busybox到Android平台
  7. android 上传文件到服务器
  8. android关机充电的奥妙所在(留着以后用)
  9. 【Android】 dialog 设置maxHeight 最大
  10. Android Handler不同界面发送数据