Android(安卓)高仿【优酷】圆盘旋转菜单 的实现
16lz
2021-01-26
Android 高仿【优酷】圆盘旋转菜单 的实现
分类:android 2012-08-22 08:16 1393人阅读 评论(9) 收藏 举报目前,用户对安卓应用程序的UI设计要求越来越高,因此,掌握一些新颖的设计很有必要.
比如菜单,传统的菜单已经不能满足用户的需求. 其中优酷中圆盘旋转菜单的实现就比较优秀,这里我提供下我的思路及实现,仅供参考.
该菜单共分里外三层导航菜单.可以依次从外向里关闭三层菜单,也可以反向打开,并且伴有圆盘旋转的动画效果
首先,看下效果:
以下是具体的代码及解释:
1. 菜单布局文件:
大家看到主要有三个RalativeLayout,就是大家看到的三层,但是关于图片的倾斜 是怎样实现的呢?实际上是个假象,图片是正放的,里面图像是倾斜的
[java] view plain copy- <RelativeLayoutxmlns: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; [java] view plain copy
- importandroid.os.Bundle;
- importandroid.app.Activity;
- importandroid.view.Menu;
- importandroid.view.View;
- importandroid.view.View.OnClickListener;
- importandroid.widget.ImageButton;
- importandroid.widget.RelativeLayout;
- publicclassMainActivityextendsActivity{
- privateImageButtonhome;
- privateImageButtonmenu;
- privateRelativeLayoutlevel2;
- privateRelativeLayoutlevel3;
- privatebooleanisLevel2Show=true;
- privatebooleanisLevel3Show=true;
- @Override
- publicvoidonCreate(BundlesavedInstanceState){
- 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(newOnClickListener(){
- @Override
- publicvoidonClick(Viewv){
- if(isLevel3Show){
- //隐藏3级导航菜单
- MyAnimation.startAnimationOUT(level3,500,0);
- }else{
- //显示3级导航菜单
- MyAnimation.startAnimationIN(level3,500);
- }
- isLevel3Show=!isLevel3Show;
- }
- });
- home.setOnClickListener(newOnClickListener(){
- @Override
- publicvoidonClick(Viewv){
- 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: [java] view plain copy
- importandroid.view.View;
- importandroid.view.ViewGroup;
- importandroid.view.animation.Animation;
- importandroid.view.animation.Animation.AnimationListener;
- importandroid.view.animation.RotateAnimation;
- publicclassMyAnimation{
- //入动画
- publicstaticvoidstartAnimationIN(ViewGroupviewGroup,intduration){
- for(inti=0;i<viewGroup.getChildCount();i++){
- viewGroup.getChildAt(i).setVisibility(View.VISIBLE);//设置显示
- viewGroup.getChildAt(i).setFocusable(true);//获得焦点
- viewGroup.getChildAt(i).setClickable(true);//可以点击
- }
- Animationanimation;
- /**
- *旋转动画
- *RotateAnimation(fromDegrees,toDegrees,pivotXType,pivotXValue,pivotYType,pivotYValue)
- *fromDegrees开始旋转角度
- *toDegrees旋转到的角度
- *pivotXTypeX轴参照物
- *pivotXValuex轴旋转的参考点
- *pivotYTypeY轴参照物
- *pivotYValueY轴旋转的参考点
- */
- animation=newRotateAnimation(-180,0,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,1.0f);
- animation.setFillAfter(true);//停留在动画结束位置
- animation.setDuration(duration);
- viewGroup.startAnimation(animation);
- }
- //出动画
- publicstaticvoidstartAnimationOUT(finalViewGroupviewGroup,intduration,intstartOffSet){
- Animationanimation;
- animation=newRotateAnimation(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(newAnimationListener(){
- @Override
- publicvoidonAnimationStart(Animationanimation){
- //TODOAuto-generatedmethodstub
- }
- @Override
- publicvoidonAnimationRepeat(Animationanimation){
- //TODOAuto-generatedmethodstub
- }
- @Override
- publicvoidonAnimationEnd(Animationanimation){
- for(inti=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(安卓)之后 II
- android:同时弹出顶部和底部菜单的做法
- Android之framework修改底部导航栏NavigationBar动态显示和隐藏
- Android菜单系统介绍
- Android(安卓)解决android4.0系统中菜单(Menu)添加Icon无效问题
- 【Android(安卓)开发】:UI控件之 ImageView 实现图片旋转和缩放功
- Android仿人人客户端(v5.7.1)——有关滑动式左侧菜单实现过程中网
- android动画的透明度渐变、旋转动画、缩放动画、评议动画
- Android(安卓)实现底部导航切换的几种方式