10、优酷菜单
来源:互联网 发布:如何添加wifi网络连接 编辑:程序博客网 时间:2024/05/16 15:28
--------------------------------main.java-------------------------
package com.example.fe;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
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 ActionBarActivity
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;
@Override
protected 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);
//3级菜单栏
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);
}
@Override
public 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.example.fe;
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);
}
}
。。。。。。。。。。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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<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/icon_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/icon_home" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/level2"
android:layout_width="180dp"
android:layout_height="90dp"
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:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:background="@drawable/icon_search" />
<ImageView
android: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" />
<ImageView
android: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>
<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: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"
/>
<ImageView
android: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" />
<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:layout_marginBottom="6dp"
android:layout_marginLeft="30dp"
android:background="@drawable/channel3" />
<ImageView
android: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"
/>
<ImageView
android: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" />
<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:layout_marginBottom="6dp"
android:layout_marginRight="30dp"
android:background="@drawable/channel5" />
</RelativeLayout>
</RelativeLayout>
- 10、优酷菜单
- 模仿优酷菜单
- 优酷菜单
- 优酷的菜单
- 模仿优酷菜单
- 文件浏览器 + 优酷菜单 + 下拉菜单 + 自定义开关按钮
- 自定义控件--优酷菜单
- 自定义控件--优酷菜单
- 自定义控件--优酷菜单
- 优酷的菜单效果
- 自定义view-优酷菜单
- 类似优酷的圆盘菜单实现
- Android优酷菜单组件自定义
- Android自定义控件---优酷菜单
- android仿老式优酷菜单
- 旋转菜单之优酷视频
- 浅谈优酷菜单的实现
- 自定义控件之优酷菜单
- 黑马程序员---oc Foundation
- intellij idea 热部署 jrebel 详细配置
- xcode界面翻译
- 关于在Mac下用Unix命令操作移动硬盘的步骤
- 响一声吸费电话代理加盟邀您共同成功
- 10、优酷菜单
- 修改mdev配置支持SD卡自动挂载
- 0, \0, NULL的区别
- 概率论--古典概型和几何概型
- Java程序员从笨鸟到菜鸟全部博客目录
- Binary system_____(Bin 神 OJ)
- 计算机图形学上机实验之DDV算法
- 吸费电话加盟 加值电话代理 货到付款
- 浏览器兼容之JavaScript篇——已在IE、FF、Chrome测试