Android UI-底部旋转菜单栏

简介:

以前都是说每逢佳节倍思亲,现在的工作状态是每到周末倍亲切,年底真的是加班加的没完没了的,也没时间写博客,也没时间学习,周末闲来无事看到一个比较有意思的旋转菜单,没事自己实战了一下感觉还不错,代码倒是没什么,主要是有两个技术点,一个就是布局文件,第二个就是动画旋转,关于布局文件是仁者见仁智者见智,只能自己研究,动画的话之前写过这方面的文章有兴趣的可以看下本人之前的博客,开始正题吧:

基础布局

先看下要实现的效果吧:

 

下面的主要是三个图片,一个半圆,两个版圆环,最外面的是三级菜单,中间的是二级菜单;

一级菜单布局:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<RelativeLayout
      android:id= "@+id/menuFirst"
      android:layout_width= "100dp"
      android:layout_height= "50dp"
      android:layout_alignParentBottom= "true"
      android:layout_centerHorizontal= "true"
      android:background= "@drawable/menu1"  >
 
      <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>

二级菜单布局:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<RelativeLayout
     android:id= "@+id/menuSecond"
     android:layout_width= "170dp"
     android:layout_height= "90dp"
     android:layout_alignParentBottom= "true"
     android:layout_centerHorizontal= "true"
     android:background= "@drawable/menu2"  >
 
     <ImageView
         android:id= "@+id/icon_search"
         android:layout_width= "wrap_content"
         android:layout_height= "wrap_content"
         android:layout_alignParentBottom= "true"
         android:layout_margin= "8dp"
         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_center"
         android:layout_width= "wrap_content"
         android:layout_height= "wrap_content"
         android:layout_alignParentBottom= "true"
         android:layout_alignParentRight= "true"
         android:layout_margin= "8dp"
         android:background= "@drawable/icon_center"  />
</RelativeLayout>

三级菜单布局,这个布局的时候需要注意的是左边的三个图片设置完之后,设置的是对称方向的最底部的一个图片,以此为依据搞定其他两个图标:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<RelativeLayout
       android:id= "@+id/menuThird"
       android:layout_width= "270dp"
       android:layout_height= "140dp"
       android:layout_alignParentBottom= "true"
       android:layout_centerHorizontal= "true"
       android:background= "@drawable/menu3"  >
 
       <ImageView
           android:id= "@+id/channel1"
           android:layout_width= "wrap_content"
           android:layout_height= "wrap_content"
           android:layout_alignParentBottom= "true"
           android:layout_marginBottom= "8dp"
           android:layout_marginLeft= "8dp"
           android:background= "@drawable/channel1"  />
 
       <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= "8dp"
           android:layout_marginLeft= "16dp"
           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= "8dp"
           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:layout_alignParentBottom= "true"
           android:layout_alignParentRight= "true"
           android:layout_marginBottom= "8dp"
           android:layout_marginRight= "8dp"
           android:background= "@drawable/channel7"  />
 
       <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= "8dp"
           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= "8dp"
           android:layout_marginRight= "30dp"
           android:background= "@drawable/channel5"  />
   </RelativeLayout>

实现Demo

主要实现的主要就是两个按钮,一个按钮式最底层的按钮,一个是二级菜单的按钮:

1
2
3
4
5
6
7
homeView = (ImageView) findViewById(R.id.icon_home);
menuView = (ImageView) findViewById(R.id.icon_menu);
menuFirst = (RelativeLayout) findViewById(R.id.menuFirst);
menuSecond = (RelativeLayout) findViewById(R.id.menuSecond);
menuThird = (RelativeLayout) findViewById(R.id.menuThird);
homeView.setOnClickListener( this );
menuView.setOnClickListener( this );

两个按钮的点击事件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@Override
public  void  onClick(View v) {
     // TODO Auto-generated method stub
     switch  (v.getId()) {
     case  R.id.icon_home:
         if  (isSecond) {
             MyHelper.StartAninationOut(menuSecond, 500 , 200 );
             if  (isThird) {
                 MyHelper.StartAninationOut(menuThird, 500 , 300 );
                 isThird= false ;
             }
         } else  {
             MyHelper.StartAninationIn(menuSecond, 500 , 300 );
         }
         isSecond=!isSecond;
         break ;
     case  R.id.icon_menu:
         if  (isThird) {
             MyHelper.StartAninationOut(menuThird, 500 , 200 );
             isThird= false ;
         } else  {
             MyHelper.StartAninationIn(menuThird, 500 , 200 );
             isThird= true ;
         }
         break ;
     default :
         break ;
     }
}

 两个按钮都有点击点击事件,封装一个可以主要就是淡入和淡出的效果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public  class  MyHelper {
 
     public  static  void  StartAninationIn(RelativeLayout layout, long  duratoin, long  offset) {
         // TODO Auto-generated method stub
         RotateAnimation rotateAnimation= new  RotateAnimation( 180 360 , layout.getWidth()/ 2 , layout.getHeight());
         rotateAnimation.setDuration(duratoin);
         rotateAnimation.setFillAfter( true ); //保持旋转之后的状态
         rotateAnimation.setStartOffset(offset); //延迟加载时间
         layout.startAnimation(rotateAnimation);
     }
 
     public  static  void  StartAninationOut(RelativeLayout layout, long  duratoin, long  offset) {
         // TODO Auto-generated method stub
         RotateAnimation rotateAnimation= new  RotateAnimation( 0 180 , layout.getWidth()/ 2 , layout.getHeight());
         rotateAnimation.setDuration(duratoin);
         rotateAnimation.setFillAfter( true );
         rotateAnimation.setStartOffset(offset);
         layout.startAnimation(rotateAnimation);
     }
 
}

 最后看下效果图:

本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4162283.html,如需转载请自行联系原作者

相关文章
|
23天前
|
存储 搜索推荐 Java
探索安卓开发中的自定义视图:打造个性化UI组件Java中的异常处理:从基础到高级
【8月更文挑战第29天】在安卓应用的海洋中,一个独特的用户界面(UI)能让应用脱颖而出。自定义视图是实现这一目标的强大工具。本文将通过一个简单的自定义计数器视图示例,展示如何从零开始创建一个具有独特风格和功能的安卓UI组件,并讨论在此过程中涉及的设计原则、性能优化和兼容性问题。准备好让你的应用与众不同了吗?让我们开始吧!
|
23天前
|
编解码 Android开发
【Android Studio】使用UI工具绘制,ConstraintLayout 限制性布局,快速上手
本文介绍了Android Studio中使用ConstraintLayout布局的方法,通过创建布局文件、设置控件约束等步骤,快速上手UI设计,并提供了一个TV Launcher界面布局的绘制示例。
31 1
|
1月前
|
API Android开发
Android项目架构设计问题之选择和使用合适的UI库如何解决
Android项目架构设计问题之选择和使用合适的UI库如何解决
38 0
|
2月前
|
XML Android开发 数据格式
Android 中如何设置activity的启动动画,让它像dialog一样从底部往上出来
在 Android 中实现 Activity 的对话框式过渡动画:从底部滑入与从顶部滑出。需定义两个 XML 动画文件 `activity_slide_in.xml` 和 `activity_slide_out.xml`,分别控制 Activity 的进入与退出动画。使用 `overridePendingTransition` 方法在启动 (`startActivity`) 或结束 (`finish`) Activity 时应用这些动画。为了使前 Activity 保持静止,可定义 `no_animation.xml` 并在启动新 Activity 时仅设置新 Activity 的进入动画。
54 12
|
2月前
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
【7月更文挑战第28天】随着移动应用市场的发展,用户对界面设计的要求不断提高。Material Design是由Google推出的设计语言,强调真实感、统一性和创新性,通过模拟纸张和墨水的物理属性创造沉浸式体验。它注重色彩、排版、图标和布局的一致性,确保跨设备的统一视觉风格。Android Studio提供了丰富的Material Design组件库,如按钮、卡片等,易于使用且美观。
87 1
|
2月前
|
Android开发 UED
Android采用Scroller实现底部二楼效果
Android采用Scroller实现底部二楼效果
28 0
Android采用Scroller实现底部二楼效果
|
3月前
|
Android开发 开发者
Android UI设计中,Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等,定义在`styles.xml`。
【6月更文挑战第26天】Android UI设计中,Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等,定义在`styles.xml`。要更改主题,首先在该文件中创建新主题,如`MyAppTheme`,覆盖所需属性。然后,在`AndroidManifest.xml`中应用主题至应用或特定Activity。运行时切换主题可通过重新设置并重启Activity实现,或使用`setTheme`和`recreate()`方法。这允许开发者定制界面并与品牌指南匹配,或提供多主题选项。
44 6
|
3月前
|
开发工具 Android开发 开发者
Android `.9.png` 图像是用于UI的可拉伸格式,保持元素清晰度和比例
【6月更文挑战第26天】Android `.9.png` 图像是用于UI的可拉伸格式,保持元素清晰度和比例。通过边上的黑线定义拉伸区域,右下角黑点标识内容区域,适应文本或组件大小变化。常用于按钮、背景等,确保跨屏幕尺寸显示质量。Android SDK 提供`draw9patch.bat`工具来创建和编辑。**
222 6
|
3月前
|
API Android开发 开发者
`RecyclerView`是Android API 21引入的UI组件,用于替代ListView和GridView
【6月更文挑战第26天】`RecyclerView`是Android API 21引入的UI组件,用于替代ListView和GridView。它提供高效的数据视图复用,优化的布局管理,支持多种布局(如线性、网格),并解耦数据、适配器和视图。RecyclerView的灵活性、性能(如局部刷新和动画支持)和扩展性使其成为现代Android开发的首选,特别是在处理大规模数据集时。
45 2
|
Android开发
《Android UI基础教程》——导读
本节书摘来自异步社区《Android UI基础教程》一书中的目录,作者 【美】Jason Ostrander,更多章节内容可以访问云栖社区“异步社区”公众号查看
787 0

热门文章

最新文章