关于这个菜单应该在很多播放器应用里面可以看见,直接先上两张效果图吧,一张是该Demo的效果图,一张是优酷手机客户端的效果图。

                                                       

DEMO的效果图                                                                   优酷手机客户端界面

因为没有时间去自己制作图标,所以Demo里面采用的就是优酷手机客户端里的图标了。

一、布局

首先从效果图中可以看出来,该菜单界面分成了三层,所以,我们采用RelativeLayout布局方式来排列这三层菜单背景。

其次,在每一层菜单中,每一个图标也是相对于自己菜单级有固定位置的,所以每一个菜单级也采用RelativeLayout布局方式。

既然布局方式都分析清楚了,那么就可以直接开始写布局文件了。需要注意的就是,每一个图标之间相对位置的摆放,这样才能使整体效果更好。

<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"
tools:context=".MainActivity" > <RelativeLayout
android:id="@+id/level1"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/level1" > <ImageView
android:id="@+id/icon_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon_home"
android:layout_centerInParent="true"/>
</RelativeLayout> <RelativeLayout
android:id="@+id/level2"
android:layout_width="180dip"
android:layout_height="90dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/level2" > <ImageView
android:id="@+id/icon_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon_search"
android:layout_alignParentBottom="true"
android:layout_margin="10dip"/> <ImageView
android:id="@+id/icon_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon_menu"
android:layout_marginTop="5dip"
android:layout_centerHorizontal="true"/> <ImageView
android:id="@+id/icon_myyouku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/icon_myyouku"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="10dip"/> </RelativeLayout> <RelativeLayout
android:id="@+id/level3"
android:layout_width="280dip"
android:layout_height="140dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/level3" > <ImageView
android:id="@+id/channel1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/channel1"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dip"
android:layout_marginBottom="10dip"/> <ImageView
android:id="@+id/channel2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/channel2"
android:layout_above="@id/channel1"
android:layout_alignLeft="@id/channel1"
android:layout_marginLeft="18dip"
android:layout_marginBottom="6dip"/> <ImageView
android:id="@+id/channel3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/channel2"
android:layout_alignLeft="@id/channel2"
android:background="@drawable/channel3"
android:layout_marginLeft="30dip"
android:layout_marginBottom="6dip"/> <ImageView
android:id="@+id/channel4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/channel4"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dip"/> <ImageView
android:id="@+id/channel7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/channel7"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"/> <ImageView
android:id="@+id/channel6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/channel6"
android:layout_above="@id/channel7"
android:layout_alignRight="@id/channel7"
android:layout_marginRight="18dip"
android:layout_marginBottom="6dip"/> <ImageView
android:id="@+id/channel5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/channel6"
android:layout_alignRight="@id/channel6"
android:background="@drawable/channel5"
android:layout_marginRight="30dip"
android:layout_marginBottom="6dip"/> </RelativeLayout> </RelativeLayout>

二、MainActivity加载布局文件

在MainActivity.java中,通过onCreate()方法,来加载出布局文件。

三、实现动画效果和点击事件

首先分析可以得出,每一级菜单消失和出现的动画都是相似的,所以可以在此建立一个工具类,来统一编写动画效果的代码,在此建立MyUtils.java

整体的动画效果就分为,消失和出现,所以只用实现这两个方法就好了。

	/**
* 出现的动画效果
	 * @param view   需要动画效果的view
         * @startOffset  需要延时执行的时间
*/
public static void startAnimIn(RelativeLayout view, int startOffset) {
RotateAnimation animation = new RotateAnimation(180, 360, view.getWidth()/2, view.getHeight());
animation.setDuration(500); // 设置运行的时间
animation.setFillAfter(true); // 动画执行完以后保持最后的状态
animation.setStartOffset(startOffset);        // 设置延时执行的时间
view.startAnimation(animation);
}
在代码中,采用了RotateAnimation这个类,来控制view的动画效果。
我们需要的是一个旋转的动画效果,所以我们需要知道默认圆心为 view的左上角,在此需要设置为 view的中心,即(view.getWidth()/2, view.getHeight())
根据同样的道理,只需要修改一样动画效果的旋转角度,就可以写出消失动画的效果
	/**
* 让指定view 延时执行旋转离开的动画
* @param view
* @param i 延时时间
*/
public static void startAnimOut(RelativeLayout view, int startOffset) { RotateAnimation animation = new RotateAnimation(0, 180, view.getWidth()/2, view.getHeight());
animation.setDuration(500); // 设置运行的时间
animation.setFillAfter(true); // 动画执行完以后保持最后的状态
animation.setStartOffset(startOffset); // 设置延时执行的时间
view.startAnimation(animation);
}
动画效果的类完成之后,就可以返回MainActivity中去监听按键的点击事件了。
	@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.icon_menu: // 处理menu图标的点击事件
// 如果第三级菜单是显示状态,则将其隐藏
if(isLevel3Show) {
// 隐藏
MyUtils.startAnimOut(level3,0);
} else {
// 显示
MyUtils.startAnimIn(level3,0);
} isLevel3Show = !isLevel3Show; break; case R.id.icon_home: // 处理home图标的点击事件
// 如果二级菜单是显示状态,那么就隐藏2,3级菜单
if(isLevel2Show ) {
MyUtils.startAnimOut(level2,0);
isLevel2Show = false;
if(isLevel3Show) {
MyUtils.startAnimOut(level3,200);
isLevel3Show = false;
}
} else {
// 如果二级菜单是隐藏状态,那么就显示2级菜单
MyUtils.startAnimIn(level2,0);
isLevel2Show = true;
}
break; default:
break;
}
}
最后就是修改Menu按键的事件,使按下Menu可以隐藏或显示全部菜单的效果。

四、Demo下载

点我下载Demo   o(︶︿︶)o

Android--简单的三级菜单的更多相关文章

  1. Python3学习之路~2.5 简单的三级菜单程序

    程序:三级菜单 需求: 1.打印省.市.县三级菜单2.可返回上一级3.可随时退出程序 代码1: data={ "山东":{ "济南":["历下区&qu ...

  2. Python实现简单的三级菜单

    话不多说,直奔代码 # 要处理的字典 dic1 = { '北京': { '东城': { '沙河': ['沙河机场', '链家'], '天通苑': ['北方明珠', '天通尾货'] }, '朝阳': { ...

  3. 三级菜单的实现(python程序)

    这是刚开始写程序,三级菜单的程序基本是用字典实现,很low,以后学习了其他更好的东西,我会继续上传,然后争取在我水平高深之后,把这个简单的东西实现的狠高大上. _author_ = "zha ...

  4. android 三级菜单 BaseExpandableListAdapter

    在网上搜了非常长时间.没有找到合适的Android三级菜单.所以就自己动手写了一个,主要使用了BaseExpandableList来实现,通过三个布局文件来完毕相应的菜单项,详细实现请參照下图. wa ...

  5. Python_简单三级菜单制作

    一:制作要求 1.三级菜单 2.可依次选择进入各子菜单 3.所需新知识点:字典,列表 *本文通过三种方法完成,第一种:只使用循环,第二种:使用列表,第三种:使用字典 二:FlowChart流程图 与上 ...

  6. Android自己定义控件:老版优酷的三级菜单(效果图 + Demo)

    效果图: 制作思路: 1.先分析这个效果,事实上能够理解为把三级菜单分成level1,level2,level3,level1是始终显示的. 点击level1后,level2会出现:点击level2后 ...

  7. Python学习-------------------三级菜单简单版

    题目: 多级菜单         1.三级菜单         2.可依次选择进入的各子菜单         3.所需新知识点:列表.字典 ReadMe: 这个做循环,比较绕脑子 点开运行即可 Min ...

  8. HTML+CSS实现简单三级菜单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. python(5)- 简单练习:python三级菜单优化

    python三级菜单优化,菜鸟版链接:http://www.cnblogs.com/xuyaping/p/6648170.html menu = { '北京':{ '海淀':{ '五道口':{ 'so ...

  10. css三级菜单效果

    一个简单实用的css三级菜单效果 <!doctype html> <html> <head> <meta charset="utf-8"& ...

随机推荐

  1. 【JDBC】预编译SQL与防注入式攻击

    在JDBC编程中,常用Statement.PreparedStatement 和 CallableStatement三种方式来执行查询语句,其中 Statement 用于通用查询, PreparedS ...

  2. linux知识积累

                                                         linux 操作系统一.linux 操作系统概述   简介            Linux是 ...

  3. ubuntu 如何在recovery模式修改root密码

    今天遇到一个问题, 前提1: ubuntu系统的root密码我一直没有设定  前提2: ubuntu初始创建的sudo用户不知道怎么移除sudo权限用户了. 下面就精彩了, 首先没有root密码,你不 ...

  4. [1.1]Knowledge that should be prepared

    Actually, there are a huge amount of knowledge we need to learn. So I hope you don't be scared. It's ...

  5. Cygwin解决Windows远程登录linux服务器

    下载地址http://www.cygwin.com/install.html 选择mirror.htnshost.com网站下载的比较快. 安装Cygwin(/X)需要选择的包: openssh(必选 ...

  6. 【转】web测试内容及工具经典总结

    基于Web的系统测试在基于Web的系统开发中,如果缺乏严格的过程,我们在开发.发布.实施和维护Web的过程中,可能就会碰到一些严重的问题,失败的可能性很大.而且,随着基于Web的系统变得越来越复杂,一 ...

  7. TCP/IP协议知识科普

    简介 本文主要介绍了工作中常用的TCP/IP对应协议栈相关基础知识,科普文. 本博客所有文章:http://www.cnblogs.com/xuanku/p/index.html TCP/IP网络协议 ...

  8. iOS viewDidUnload方法

    转自:http://blog.csdn.net/chun799/article/details/8951694 在iOS6中,viewDidUnload回调方法被Deprecated掉了.查看苹果的文 ...

  9. PHP: 深入pack/unpack 字节序

    http://my.oschina.net/goal/blog/195749?p=1 目录[-] 写在前面的话 什么是字节序 MSB和LSB 大端序 小端序 网络字节序 主机字节序 总结 pack/u ...

  10. QQWry.dat 数据写入

    纯真IP库 数据多,更新及时,很多同学在用,网上关于其读取的帖子也有不少(当然其中有一些是有BUG的),但却很少有关于其写入的帖子.OK,下面分享下写QQWry.dat. QQWry.dat 分三个部 ...