关于这个菜单应该在很多播放器应用里面可以看见,直接先上两张效果图吧,一张是该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. VMware搭建12.0搭建Mac OS10.11详细过程

    1.软件准备 1.1VMware12.0 1.2VMware增强包 1.3Mac OS10.11 cdr(相当于dmg) 1.4securable.exe 2.软件破解 2.1VMware输入序列号破 ...

  2. 数据库连接字符串ConnectionString 中的关键字值释义

    ConnectionString 类似于 OLE DB 连接字符串,但并不相同.与 OLE DB 或 ADO不同,如果“Persist Security Info ”值设置为false(默认值),则返 ...

  3. C#全角半角转换函数

    Code#region 全角半角转换 /// <summary> /// 转全角的函数(SBC case) /// </summary> /// <param name= ...

  4. C#客户端链接网页需要用到的WebClient

    WebClient 类提供向 URI 标识的任何本地.Intranet 或 Internet 资源发送数据以及从这些资源接收数据的公共方法. WebClient 类使用 WebRequest 类提供对 ...

  5. python中List操作

    传送门 官方文件地址 list.append(x): 将x加入列表尾部,等价于a[len(a):] = [x] 例: >>> list1=[1,2,3,4] >>> ...

  6. CSS3实现翻转菜单效果

    演示地址 点击打开链接 注意:菜单翻转效果在搜狗浏览器上看不出来.推荐用FireFox <!DOCTYPE   html   PUBLIC   "-//W3C//DTD XHTML 1 ...

  7. Klist

    显示当前缓存的 Kerberos 票证的列表. 有关如何使用此命令的示例 语法 klist [-<LogonId.HighPart> lh] [-li <LogonId.LowPar ...

  8. URAL 1776 C - Anniversary Firework DP

    C - Anniversary FireworkTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...

  9. windows command ftp 中文文件名乱码解决方法

    有时,使用临时的windows机子,要进行ftp简单操作,但又不想装其它的ftp-client,可以直接使用windows command中的命令ftp来操作. 通常,ftp服务器按标准,使用utf8 ...

  10. .Net枚举类型小结

    1.枚举类型的要点: (1)类型声明语法: enum 枚举名 (2)枚举体语法: a.成员名称 = 整数值,其他成员名称,或者其他成员与整数的表达式  b.成员之间需要用逗号隔开 (3)枚举可以继承的 ...