全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

Android编程实现仿优酷圆盘旋转菜单效果的方法详解【附demo源码下载】

本文实例讲述了Android编程实现仿优酷圆盘旋转菜单效果的方法。分享给大家供大家参考,具体如下:

目前,用户对安卓应用程序的UI设计要求越来越高,因此,掌握一些新颖的设计很有必要.

比如菜单,传统的菜单已经不能满足用户的需求. 其中优酷中圆盘旋转菜单的实现就比较优秀,这里我提供下我的思路及实现,仅供参考.

该菜单共分里外三层导航菜单.可以依次从外向里关闭三层菜单,也可以反向打开,并且伴有圆盘旋转的动画效果

首先,看下效果:

以下是具体的代码及解释:

1. 菜单布局文件:

大家看到主要有三个RalativeLayout,就是大家看到的三层,但是关于图片的倾斜 是怎样实现的呢?实际上是个假象,图片是正放的,里面图像是倾斜的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >
  <RelativeLayout
    android:layout_width="100dip"
    android:layout_height="50dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/level1" >
    <ImageButton
      android:id="@+id/home"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:background="@drawable/icon_home" />
  </RelativeLayout>
  <RelativeLayout
    android:layout_width="180dip"
    android:layout_height="90dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:id="@+id/level2"
    android:background="@drawable/level2" >
    <ImageButton
      android:id="@+id/search"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_margin="10dip"
      android:background="@drawable/icon_search" />
    <ImageButton
      android:id="@+id/menu"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_margin="6dip"
      android:background="@drawable/icon_menu" />
    <ImageButton
      android:id="@+id/myyouku"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:layout_margin="10dip"
      android:background="@drawable/icon_myyouku" />
  </RelativeLayout>
  <RelativeLayout
    android:layout_width="280dip"
    android:layout_height="140dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:id="@+id/level3"
    android:background="@drawable/level3" >
    <ImageButton
      android:id="@+id/c1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_marginBottom="6dip"
      android:layout_marginLeft="12dip"
      android:background="@drawable/channel1" />
    <ImageButton
      android:id="@+id/c2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@id/c1"
      android:layout_marginBottom="12dip"
      android:layout_marginLeft="28dip"
      android:background="@drawable/channel2" />
    <ImageButton
      android:id="@+id/c3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@id/c2"
      android:layout_marginBottom="6dip"
      android:layout_marginLeft="8dip"
      android:layout_toRightOf="@id/c2"
      android:background="@drawable/channel3" />
    <ImageButton
      android:id="@+id/c4"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_margin="6dip"
      android:background="@drawable/channel4" />
        <ImageButton
      android:id="@+id/c5"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/c6"
      android:layout_marginBottom="6dip"
      android:layout_marginRight="8dip"
      android:layout_toLeftOf="@+id/c6"
      android:background="@drawable/channel5" />
        <ImageButton
      android:id="@+id/c6"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/c7"
      android:layout_marginBottom="12dip"
      android:layout_marginRight="28dip"
      android:layout_alignParentRight="true"
      android:background="@drawable/channel6" />
        <ImageButton
      android:id="@+id/c7"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_marginBottom="6dip"
      android:layout_marginRight="12dip"
      android:layout_alignParentRight="true"
      android:background="@drawable/channel7" />
  </RelativeLayout>
</RelativeLayout>

2. MainActivity;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
  private ImageButton home;
  private ImageButton menu;
  private RelativeLayout level2;
  private RelativeLayout level3;
  private boolean isLevel2Show = true;
  private boolean isLevel3Show = true;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    home = (ImageButton) findViewById(R.id.home);
    menu = (ImageButton) findViewById(R.id.menu);
    level2 = (RelativeLayout) findViewById(R.id.level2);
    level3 = (RelativeLayout) findViewById(R.id.level3);
    menu.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        if(isLevel3Show){
          //隐藏3级导航菜单
          MyAnimation.startAnimationOUT(level3, 500, 0);
        }else {
          //显示3级导航菜单
          MyAnimation.startAnimationIN(level3, 500);
        }
        isLevel3Show = !isLevel3Show;
      }
    });
    home.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        if(!isLevel2Show){
          //显示2级导航菜单
          MyAnimation.startAnimationIN(level2, 500);
        } else {
          if(isLevel3Show){
            //隐藏3级导航菜单
            MyAnimation.startAnimationOUT(level3, 500, 0);
            //隐藏2级导航菜单
            MyAnimation.startAnimationOUT(level2, 500, 500);
            isLevel3Show = !isLevel3Show;
          }
          else {
            //隐藏2级导航菜单
            MyAnimation.startAnimationOUT(level2, 500, 0);
          }
        }
        isLevel2Show = !isLevel2Show;
      }
    });
  }
}

3. 自定义动画类MyAnimation:

import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.RotateAnimation;
public class MyAnimation {
  //入动画
  public static void startAnimationIN(ViewGroup viewGroup, int duration){
    for(int i = 0; i < viewGroup.getChildCount(); i++ ){
      viewGroup.getChildAt(i).setVisibility(View.VISIBLE);//设置显示
      viewGroup.getChildAt(i).setFocusable(true);//获得焦点
      viewGroup.getChildAt(i).setClickable(true);//可以点击
    }
    Animation animation;
    /**
     * 旋转动画
     * RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue)
     * fromDegrees 开始旋转角度
     * toDegrees 旋转到的角度
     * pivotXType X轴 参照物
     * pivotXValue x轴 旋转的参考点
     * pivotYType Y轴 参照物
     * pivotYValue Y轴 旋转的参考点
     */
    animation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
    animation.setFillAfter(true);//停留在动画结束位置
    animation.setDuration(duration);
    viewGroup.startAnimation(animation);
  }
  //出动画
  public static void startAnimationOUT(final ViewGroup viewGroup, int duration , int startOffSet){
    Animation animation;
    animation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
    animation.setFillAfter(true);//停留在动画结束位置
    animation.setDuration(duration);
    animation.setStartOffset(startOffSet);
    animation.setAnimationListener(new AnimationListener() {
      @Override
      public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub
      }
      @Override
      public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
      }
      @Override
      public void onAnimationEnd(Animation animation) {
        for(int i = 0; i < viewGroup.getChildCount(); i++ ){
          viewGroup.getChildAt(i).setVisibility(View.GONE);//设置显示
          viewGroup.getChildAt(i).setFocusable(false);//获得焦点
          viewGroup.getChildAt(i).setClickable(false);//可以点击
        }
      }
    });
    viewGroup.startAnimation(animation);
  }
}

这样,一个*优酷三级导航圆盘旋转菜单就完成了.,以后完全可以借鉴这些优秀的UI设计,甚至根据新的需求,可以做出更好的UI.

附:完整实例代码点击此处本站下载

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android布局layout技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。


# Android  # 仿优酷  # 圆盘旋转  # 菜单效果  # Android 自定义组件卫星菜单的实现  # Android卫星菜单效果的实现方法  # Android自定义VIew实现卫星菜单效果浅析  # Android实现自定义的卫星式菜单(弧形菜单)详解  # Android学习教程之圆形Menu菜单制作方法(1)  # Android自定义view实现圆形与半圆形菜单  # Android圆形旋转菜单开发实例  # Android自定义ViewGroup实现带箭头的圆角矩形菜单  # Android仿优酷圆形菜单学习笔记分享  # Adapter模式实战之重构鸿洋集团的Android圆形菜单建行  # Android实现卫星菜单效果  # 停留在  # 进阶  # 是个  # 相关内容  # 很有  # 感兴趣  # 给大家  # 是怎样  # 自定义  # 点击此处  # 更多关于  # 解决方法  # 所述  # 共分  # 程序设计  # 应用程序  # 仅供参考  # 完成了  # 主要有  # 讲述了 


相关文章: 公司网站的制作公司,企业网站制作基本流程有哪些?  如何通过西部建站助手安装IIS服务器?  建站主机服务器选购指南:轻量应用与VPS配置解析  手机钓鱼网站怎么制作视频,怎样拦截钓鱼网站。怎么办?  北京网页设计制作网站有哪些,继续教育自动播放怎么设置?  建站之星展会模板:智能建站与自助搭建高效解决方案  如何在阿里云ECS服务器部署织梦CMS网站?  网站插件制作软件免费下载,网页视频怎么下到本地插件?  如何高效利用200m空间完成建站?  ,有什么在线背英语单词效率比较高的网站?  兔展官网 在线制作,怎样制作微信请帖?  建站上传速度慢?如何优化加速网站加载效率?  linux top下的 minerd 木马清除方法  建站之星如何实现五合一智能建站与营销推广?  高防服务器租用指南:配置选择与快速部署攻略  c++如何打印函数堆栈信息_c++ backtrace函数与符号名解析【方法】  山东网站制作公司有哪些,山东大源集团官网?  如何在局域网内绑定自建网站域名?  c# 在ASP.NET Core中管理和取消后台任务  ,巨量百应是干嘛的?  如何在IIS7上新建站点并设置安全权限?  如何快速查询域名建站关键信息?  合肥做个网站多少钱,合肥本地有没有比较靠谱的交友平台?  小说建站VPS选用指南:性能对比、配置优化与建站方案解析  建站之星如何防范黑客攻击与数据泄露?  小视频制作网站有哪些,有什么看国内小视频的网站,求推荐?  北京的网站制作公司有哪些,哪个视频网站最好?  如何使用Golang安装API文档生成工具_快速生成接口文档  在线教育网站制作平台,山西立德教育官网?  太原网站制作公司有哪些,网约车营运证查询官网?  免费网站制作模板下载,除了易企秀之外还有什么H5平台可以制作H5长页面,最好是免费的?  整人网站在线制作软件,整蛊网站退不出去必须要打我是白痴才能出去?  网站制作外包价格怎么算,招聘网站上写的“外包”是什么意思?  5种Android数据存储方式汇总  独立制作一个网站多少钱,建立网站需要花多少钱?  整蛊网站制作软件,手机不停的收到各种网站的验证码短信,是手机病毒还是人为恶搞?有这种手机病毒吗?  如何在阿里云通过域名搭建网站?  上海网站制作开发公司,上海买房比较好的网站有哪些?  ,网站推广常用方法?  香港服务器网站推广:SEO优化与外贸独立站搭建策略  成都响应式网站开发,dw怎么把手机适应页面变成网页?  创业网站制作流程,创业网站可靠吗?  手机网站制作与建设方案,手机网站如何建设?  宝塔Windows建站如何避免显示默认IIS页面?  广州商城建站系统开发成本与周期如何控制?  h5在线制作网站电脑版下载,h5网页制作软件?  简易网站制作视频教程,使用记事本编写一个简单的网页html文件?  如何正确下载安装西数主机建站助手?  关于BootStrap modal 在IOS9中不能弹出的解决方法(IOS 9 bootstrap modal ios 9 noticework)  企业宣传片制作网站有哪些,传媒公司怎么找企业宣传片项目? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。