iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >如何在Android中实现一个圆盘旋转菜单效果
  • 180
分享到

如何在Android中实现一个圆盘旋转菜单效果

android 2023-05-30 22:05:54 180人浏览 安东尼
摘要

本文章向大家介绍如何在Android中实现一个圆盘旋转菜单效果的基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。Android是什么Android是一种基于linux内核的自由及开放源代码的操作系统,主要使用于移动

本文章向大家介绍如何在Android中实现一个圆盘旋转菜单效果的基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Android是什么

Android是一种基于linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国Google公司和开放手机联盟领导及开发

菜单布局文件:

<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>

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;      }    });  }}

自定义动画类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;        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);  }}

以上就是小编为大家带来的如何在Android中实现一个圆盘旋转菜单效果的全部内容了,希望大家多多支持编程网!

--结束END--

本文标题: 如何在Android中实现一个圆盘旋转菜单效果

本文链接: https://www.lsjlt.com/news/221801.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 如何在Android中实现一个圆盘旋转菜单效果
    本文章向大家介绍如何在Android中实现一个圆盘旋转菜单效果的基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。Android是什么Android是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动...
    99+
    2023-05-30
    android
  • 怎么在css中实现一个旋转效果
    这篇文章给大家介绍怎么在css中实现一个旋转效果,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。css中可以实现旋转效果的属性是“transform”。transform 属性向元素应用 2D 或 3D 转换。该属性允许...
    99+
    2023-06-14
  • 怎么在html5中实现一个画布旋转效果
    今天就跟大家聊聊有关怎么在html5中实现一个画布旋转效果,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。keleyi.htm的代码如下:<!DOCTYPE HTML&...
    99+
    2023-06-09
  • 怎么在Android应用中利用Bitmap实现一个位图旋转效果
    怎么在Android应用中利用Bitmap实现一个位图旋转效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。位图的旋转也可以借助Matrix或者Canvas来实现。通过po...
    99+
    2023-05-31
    android bitmap roi
  • 如何在Android中实现一个动画效果的自定义下拉菜单功能
    如何在Android中实现一个动画效果的自定义下拉菜单功能?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。要实现的功能及思路如下:下拉菜单样式是自定义的、非原生效果:需要使用...
    99+
    2023-06-06
  • Android中DrawerLayout如何实现侧滑菜单效果
    这篇文章主要为大家展示了“Android中DrawerLayout如何实现侧滑菜单效果”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Android中DrawerLayout如何实现侧滑菜单效果”...
    99+
    2023-05-30
    drawerlayout android
  • 怎么在Android中通过自定义View实现一个箭头沿圆转动效果
    这篇文章主要为大家详细介绍了怎么在Android中通过自定义View实现一个箭头沿圆转动效果,文中示例代码介绍的非常详细,具有一定的参考价值,发现的小伙伴们可以参考一下:Android是什么Android是一种基于Linux内核的自由及开放...
    99+
    2023-05-30
    android view
  • 怎么在CSS3中实现一个酷炫的3D旋转透视效果
    本篇文章给大家分享的是有关怎么在CSS3中实现一个酷炫的3D旋转透视效果,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。CSS3 3D 转换的常用API介绍首先先上一张css 3...
    99+
    2023-06-08
  • 如何使用纯CSS实现一个旋转魔方轮播效果
    这篇文章给大家分享的是有关如何使用纯CSS实现一个旋转魔方轮播效果的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。总的来说我们需要实现以下两个主要功能:构建一个能够旋转的立方体让立...
    99+
    2022-10-19
  • 如何在Android界面中实现一个回弹效果
    这篇文章给大家介绍如何在Android界面中实现一个回弹效果,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。具体代码如下所示:public class MyScrollView extends ScrollView { ...
    99+
    2023-05-31
    android roi %d
  • 如何在Android应用中实现一个Gallery画廊效果
    这期内容当中小编将会给大家带来有关如何在Android应用中实现一个Gallery画廊效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。画廊 使用Gallery表示,按水平方向显示内容,并且可以用手指直接...
    99+
    2023-05-31
    android gallery roi
  • 如何在Android中利用ConstraintLayout实现一个动画效果
    这篇文章将为大家详细讲解有关如何在Android中利用ConstraintLayout实现一个动画效果,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。xml布局:<!-- activit...
    99+
    2023-05-31
    android constraintlayout roi
  • 如何在Android中利用TextView实现一个跑马灯效果
    本篇文章为大家展示了如何在Android中利用TextView实现一个跑马灯效果,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。Android自带的跑马灯效果不太好控制,还必须要满足条件才能有效果,而...
    99+
    2023-05-31
    android textview roi
  • 如何在Android中利用itemdecoration实现一个时间线效果
    今天就跟大家聊聊有关如何在Android中利用itemdecoration实现一个时间线效果,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。代码如下:// 时间线装饰器pub...
    99+
    2023-06-06
  • 如何在Android应用中实现一个列表悬浮效果
    这期内容当中小编将会给大家带来有关如何在Android应用中实现一个列表悬浮效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。具体方法如下:package com.xiaos.view;import an...
    99+
    2023-05-31
    android roi
  • 如何在Android中利用TextView实现一个内容居中效果
    本篇文章给大家分享的是有关如何在Android中利用TextView实现一个内容居中效果,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。1.首先自定义一个类,继承TextView...
    99+
    2023-05-31
    android textview roi
  • 如何在Android应用中利用Dialog实现一个动画效果
    今天就跟大家聊聊有关如何在Android应用中利用Dialog实现一个动画效果,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。 创建两个动画文件window_in.xml:<&a...
    99+
    2023-05-31
    android dialog roi
  • 如何在Android中利用ScrollView实现一个顶部悬停效果
    这期内容当中小编将会给大家带来有关如何在Android中利用ScrollView实现一个顶部悬停效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。原理:原理其实很简单就是对view的gone和visibl...
    99+
    2023-05-31
    android scrollview roi
  • 如何在android中利用listview实现一个列表展示效果
    今天就跟大家聊聊有关如何在android中利用listview实现一个列表展示效果,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。设置条目点击事件package com.it...
    99+
    2023-05-31
    android listview roi
  • 如何在Android应用中利用DrawerLayout实现一个侧拉菜单栏功能
    如何在Android应用中利用DrawerLayout实现一个侧拉菜单栏功能?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。activity_main.xml<&#...
    99+
    2023-05-31
    android drawerlayout roi
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作