Android 高仿优酷旋转菜单
来源:互联网 发布:windows平板游戏 编辑:程序博客网 时间:2024/06/06 09:46
这是一个很早版本的优酷菜单,效果挺不错的,实现起来也挺简单的。废话不说,直接上代码:
首先是xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <!--一级菜单--> <RelativeLayout android:id="@+id/level1" android:layout_width="100dp" android:layout_height="50dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/level1"> <ImageView android:id="@+id/id_menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:src="@drawable/icon_home" /> </RelativeLayout> <!--二级菜单--> <RelativeLayout android:id="@+id/level2" android:layout_width="180dp" android:layout_height="88dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/level2"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="5dp" android:layout_marginLeft="5dp" android:src="@drawable/icon_search" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="5dp" android:layout_marginRight="5dp" android:src="@drawable/icon_myyouku" /> <ImageView android:id="@+id/id_menu2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginBottom="5dp" android:src="@drawable/icon_menu" /> </RelativeLayout> <!--三级菜单--> <RelativeLayout android:id="@+id/level3" android:layout_width="280dp" android:layout_height="140dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/level3"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="6dp" android:layout_marginLeft="6dp" android:background="@drawable/channel1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="6dp" android:layout_marginRight="6dp" android:background="@drawable/channel5" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="45dp" android:layout_marginLeft="28dp" android:background="@drawable/channel2" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="45dp" android:layout_marginRight="28dp" android:background="@drawable/channel6" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="75dp" android:layout_marginLeft="60dp" android:background="@drawable/channel3" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="75dp" android:layout_marginRight="60dp" android:background="@drawable/channel7" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="@drawable/channel4" /> </RelativeLayout></RelativeLayout>
静态效果如下:
接下来实现关闭:
最后是activity中的实现:public static int animCount=0;//记录当初动画数量;public static void closeMenu(RelativeLayout layout,int starttime) { //处理 菜单隐藏后,view还可以被点击的bug for (int i=0;i<layout.getChildCount();i++){ layout.getChildAt(i).setEnabled(false); } RotateAnimation rotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1f); rotateAnimation.setDuration(500); rotateAnimation.setFillAfter(true); rotateAnimation.setStartOffset(starttime); rotateAnimation.setAnimationListener(new MyAnimationListeren()); layout.startAnimation(rotateAnimation);}public static void openMenu(RelativeLayout layout,int starttime) { //处理 菜单显示后,view还可以被点击恢复 for (int i=0;i<layout.getChildCount();i++){ layout.getChildAt(i).setEnabled(true); } RotateAnimation rotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,1f); rotateAnimation.setDuration(500); rotateAnimation.setFillAfter(true); rotateAnimation.setStartOffset(starttime); rotateAnimation.setAnimationListener(new MyAnimationListeren()); layout.startAnimation(rotateAnimation);}static class MyAnimationListeren implements Animation.AnimationListener{ @Override public void onAnimationStart(Animation animation) { animCount++; } @Override public void onAnimationEnd(Animation animation) { animCount--; } @Override public void onAnimationRepeat(Animation animation) { }}
public void onClick(View v) { switch (v.getId()) { case R.id.id_menu:if (AnimUtil.animCount!=0){ //当前有动画在执行,直接返回,不进行操作 return; }if (ifLevel2Show) {//需要隐藏int starttime=0;if (ifLevel3Show) {AnimUtil.closeMenu(layoutTHLevel,starttime);ifLevel3Show = !ifLevel3Show;starttime+=200; }
AnimUtil.closeMenu(layoutTLevel,starttime);} else {
//需要显示AnimUtil.openMenu(layoutTLevel); }ifLevel2Show = !ifLevel2Show;break;
case R.id.id_menu2:if (AnimUtil.animCount!=0){ //当前有动画在执行,直接返回,不进行操作 return; }if (ifLevel3Show) {//需要隐藏AnimUtil.closeMenu(layoutTHLevel,0);} else {
//需要显示AnimUtil.openMenu(layoutTHLevel);} ifLevel3Show = !ifLevel3Show; break; }}
demo链接:高仿优酷旋转菜单demo链接
0 0
- Android 高仿优酷旋转菜单
- Android圆形旋转菜单
- Android 圆形旋转菜单
- Android环形旋转菜单
- Android CircleMenu 圆形旋转菜单
- Android 圆形旋转菜单【转】
- 超炫圆形旋转菜单Android-CircleMenu
- Android自定义组件之旋转菜单
- Android之可旋转的轮盘菜单
- 旋转菜单
- 旋转菜单
- Android 高仿【优酷】圆盘旋转菜单的实现
- Android 高仿【优酷】圆盘旋转菜单的实现(转载)
- Android 高仿【优酷】圆盘旋转菜单 的实现
- Android 高仿【优酷】圆盘旋转菜单 的实现
- Android 高仿【优酷】圆盘旋转菜单的实现 .
- Android 高仿【优酷】圆盘旋转菜单的实现
- Android实现Path2.0中绚丽的的旋转菜单
- iOS判断当前控制器是否在显示
- typedef char * pStr的问题,const char *p1 = string和const pStr p2 = string的区别
- QQ5.0特效专辑
- Java Web文件下载2——文件下载乱码处理(转载)
- hdu 5387 Clock 简单数学
- Android 高仿优酷旋转菜单
- 8月22日珠海 OSC 源创会正在报名,送机械键盘和开源无码内裤
- linux shell中"2>&1"含义
- 黑马程序员_集合_list集合
- Eclipse配置Maven
- UITableViewCell drawRect画线在iOS7下不显示的问题
- 常用状态码
- hdu1570 水~水~水~
- CAS 4.0 单点登录教程