自定义控件--优酷menu
效果图:
菜单共分为三级:第一级为最下面的拱形桥,第二级为第二个拱桥,第三级为最外面的
菜单以旋转的方式显示或消失。
动画的原理如下图:
具体实现代码:
activity_main.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"tools:context=".MainActivity" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:text="@string/hello_world" /><RelativeLayoutandroid:id="@+id/level1"android:layout_width="100dp"android:layout_height="50dp"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:background="@drawable/level1" ><ImageViewandroid:id="@+id/icon_home"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:background="@drawable/icon_home" /></RelativeLayout><RelativeLayoutandroid:id="@+id/level2"android:layout_width="180dp"android:layout_height="90dp"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:background="@drawable/level2" ><ImageViewandroid:id="@+id/icon_search"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_margin="10dp"android:background="@drawable/icon_search" /><ImageViewandroid:id="@+id/icon_menu"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_marginTop="5dp"android:background="@drawable/icon_menu" /><ImageViewandroid:id="@+id/icon_myyouku"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_margin="10dp"android:background="@drawable/icon_myyouku" /></RelativeLayout><RelativeLayoutandroid: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:id="@+id/channel1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/channel1"android:layout_alignParentBottom="true"android:layout_marginLeft="10dp"android:layout_marginBottom="10dp"/><ImageViewandroid:id="@+id/channel2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/channel1"android:layout_alignLeft="@id/channel1"android:layout_marginBottom="6dp"android:layout_marginLeft="20dp"android:background="@drawable/channel2" /><ImageViewandroid:id="@+id/channel3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/channel2"android:layout_alignLeft="@id/channel2"android:layout_marginBottom="6dp"android:layout_marginLeft="30dp"android:background="@drawable/channel3" /><ImageViewandroid:id="@+id/channel4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_marginTop="5dp"android:background="@drawable/channel4" /><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_marginBottom="10dp"android:layout_marginRight="10dp"/><ImageViewandroid:id="@+id/channel6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/channel7"android:layout_alignRight="@id/channel7"android:layout_marginBottom="6dp"android:layout_marginRight="20dp"android:background="@drawable/channel6" /><ImageViewandroid:id="@+id/channel5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/channel6"android:layout_alignRight="@id/channel6"android:layout_marginBottom="6dp"android:layout_marginRight="30dp"android:background="@drawable/channel5" /></RelativeLayout></RelativeLayout>
MainActivity.java
package com.itheima.yokumenu28;import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;public class MainActivity extends Activity implements OnClickListener {private ImageView icon_menu;private ImageView icon_home;private RelativeLayout level1;private RelativeLayout level2;private RelativeLayout level3;/*** 判断 第3级菜单是否显示* true 为显示*/private boolean isLevel3Show = true;/*** 判断 第2级菜单是否显示* true 为显示*/private boolean isLevel2Show = true;/*** 判断 第1级菜单是否显示* true 为显示*/private boolean isLevel1show = true;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);icon_home = (ImageView) findViewById(R.id.icon_home);icon_menu = (ImageView) findViewById(R.id.icon_menu);level1 = (RelativeLayout) findViewById(R.id.level1);level2 = (RelativeLayout) findViewById(R.id.level2);level3 = (RelativeLayout) findViewById(R.id.level3);icon_home.setOnClickListener(this);icon_menu.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.icon_menu: //处理 menu 图标的点击事件// 如果第3级菜单是显示状态,那么将其隐藏if(isLevel3Show){//隐藏 第3级菜单MyUtils.startAnimOut(level3);}else{// 如果第3级菜单是隐藏状态,那么将其显示MyUtils.startAnimIn(level3);}isLevel3Show = !isLevel3Show;break;case R.id.icon_home: //处理 home 图标 的点击事件// 如果第2级菜单是显示状态,那么就隐藏,2,3级菜单if(isLevel2Show ){MyUtils.startAnimOut(level2);isLevel2Show = false;if(isLevel3Show){ // 如果此时,第3级菜单也显示,那也将其隐藏MyUtils.startAnimOut(level3,200);isLevel3Show = false;}}else{// 如果第2级菜单是隐藏状态,那么就显示2级菜单MyUtils.startAnimIn(level2);isLevel2Show = true;}break;}}/*** 改变第1级菜单的状态*/private void changeLevel1State() {//如果第1级菜单是显示状态,那么就隐藏 1,2,3级菜单 if(isLevel1show){MyUtils.startAnimOut(level1);isLevel1show = false;if(isLevel2Show){ // 判断2级菜单是否显示MyUtils.startAnimOut(level2,100);isLevel2Show = false;if(isLevel3Show){ // 判断3级菜单是否显示MyUtils.startAnimOut(level3,200);isLevel3Show = false;}}}else{//如果第1级菜单是隐藏状态,那么就显示 1,2级菜单 MyUtils.startAnimIn(level1);isLevel1show = true;MyUtils.startAnimIn(level2,200);isLevel2Show = true;}}@Override/*** 响应按键的动作*/public boolean onKeyDown(int keyCode, KeyEvent event) {if(keyCode == KeyEvent.KEYCODE_MENU){ // 监听 menu 按键changeLevel1State();}return super.onKeyDown(keyCode, event);}}
MyUtils.java
package com.itheima.yokumenu28;import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;public class MyUtils {/*** 让指定的view 执行 旋转离开的动画* @param view*/public static void startAnimOut(RelativeLayout view) {startAnimOut(view, 0);}/*** 让指定view 延时 执行旋转离开的动画,* @param level3* @param offset 延时的时间*/public static void startAnimOut(RelativeLayout view, long offset) {/** 默认圆为 为view的左上角,* 水平向右 为 0度* 顺时针旋转度数增加*/RotateAnimation animation =new RotateAnimation(0, 180, view.getWidth()/2, view.getHeight());animation.setDuration(500); // 设置运行的时间animation.setFillAfter(true); //动画执行完以后,保持最后的状态animation.setStartOffset(offset); // 设置延时执行的时间view.startAnimation(animation);}/*** 让指定的view 执行 旋转进入的动画* @param view*/public static void startAnimIn(RelativeLayout view) {startAnimIn(view, 0);}/*** 让指定的view 延时执行 旋转进入的动画* @param level2* @param i 延时的时间*/public static void startAnimIn(RelativeLayout view, int i) {/** 默认圆为 为view的左上角,* 水平向右 为 0度* 顺时针旋转度数增加*/RotateAnimation animation =new RotateAnimation(180, 360, view.getWidth()/2, view.getHeight());animation.setDuration(500); // 设置运行的时间animation.setFillAfter(true); //动画执行完以后,保持最后的状态animation.setStartOffset(i); //设置延时执行的时间view.startAnimation(animation);}}
自定义控件--优酷menu相关推荐
- my android tools优酷,Android自定义控件——仿优酷圆盘菜单
最近学习的时候,看见一份资料上教怎么写自定义控件,上面的示例用的是优酷早期版本的客户端,该客户端的菜单就是一个自定义的组件(现在的版本就不清楚有没有了,没下载过了),好吧,废话不多说,先上优酷的原型图 ...
- android仿优酷菜单,Android自定义控件之仿优酷菜单
去年的优酷HD版有过这样一种菜单,如下图: 应用打开之后,先是三个弧形的三级菜单,点击实体键menu之后,这三个菜单依次旋转退出,再点击实体键menu之后,一级菜单会旋转进入,点击一级菜单,二级菜单旋 ...
- Android自定义控件:优酷菜单
优酷菜单 常用控件回顾 布局文件实现 代码处理逻辑 解决bug的两种方法(ViewGroup和属性动画) 常用控件回顾 按钮控件(Button和ImageButton) ImageButton继承自I ...
- android自定义控件之模仿优酷菜单
去年的优酷HD版有过这样一种菜单,如下图: 应用打开之后,先是三个弧形的三级菜单,点击实体键menu之后,这三个菜单依次旋转退出,再点击实体键menu之后,一级菜单会旋转进入,点击一级菜单,二级菜单旋 ...
- 为什么 APP 纷纷开发“暗黑模式”?优酷最佳实践总结
简介: < 优酷 APP 全量支持"暗黑模式" 设计与技术完整总结>正式发布-- 一.缘起 随着iOS 13和Android 10的正式发布,一个名词"暗 ...
- 优酷暗黑模式(一):是什么、为什么、如何落地?
优酷主客从 20191125 版本开始,Android 和 iOS 双端均已全量支持"暗黑模式",欢迎大家试用并提出宝贵意见. 一.缘起 随着 iOS 13 和 Android 1 ...
- UI复习练习_优酷布局
UI复习练习_优酷布局 还记得前一周,细致看了一下我自己的代码,特意看了下代码规范,一个好的代码习惯就应该慢慢增加自己寻常练习中. 看看UI吧 我是想特意今天复习下曾经忽视的UI知识,事实上作为一个开 ...
- android仿优酷菜单,Android编程实现仿优酷旋转菜单效果(附demo源码)
本文实例讲述了Android编程实现仿优酷旋转菜单效果.分享给大家供大家参考,具体如下: 首先,看下效果: 不好意思,不会制作动态图片,只好上传静态的了,如果谁会,请教教我吧. 首先,看下xml文件: ...
- 优酷在线播放器 html5,GitHub - esterTion/Youku-HTML5-Player: 一个适配优酷的简单易用的HTML5播放器...
本扩展将不再维护 目前的可用性状态(19/03/16): firefox 65 基本正常使用 chrome 73 已确认无法使用 This extension is no longer maintai ...
最新文章
- 设计模式 之美 -- 策略模式
- vmware workstation 下安装ubuntu
- js检测数据类型的方法你都掌握了几个?
- 【转】makefile写法2
- 冰豹lua驱动设置_卡宴?卡宴!——冰豹ROCCAT Kain 120 AIMO开箱
- sendBroadcast和sendStickyBroadcast的区别
- 匹配滤波器结合Matlab实现
- FreebuF黑客专访系列之吴翰清(刺):接下来几年,有两样东西必定会火
- FreeSSL + ACME自动化续期域名SSL证书(支持泛域名)
- C++ 酒店管理系统
- 有限元形函数及JuliaFEM中的实现方式
- 如何一步一步成为一个领域专家
- 项目三探索 TMDb 电影数据
- Java String intern()方法
- warning:4005 DXGI_STATUS_OCCLUDED,宏重定义
- C# winform 打印预览
- 16路4k相机拍照的jpeg照片共有多大
- 从量变到质变,中国移动在5G时代或将处于不利地位
- csdn怎么让代码变得好看_是什么让游戏变得更好
- vue中使用raphael.js实现地图绘制