Android 一个炫酷的扇形菜单

效果演示

效果展示

如何使用

1、布局

<com.rance.library.SectorMenuButton    
  android:id="@+id/sector_menu"    
  android:layout_width="wrap_content"    
  android:layout_height="wrap_content"    
  app:aebAnimDurationMillis="175"    
  app:aebBlurBackground="true"    
  app:aebBlurRadius="10"    
  app:aebButtonElevation="0dp"    
  app:aebButtonGapDp="60dp"    
  app:aebEndAngleDegree="359"    
  app:aebIsSelectionMode="false"    
  app:aebMainButtonRotateAnimDurationMillis="300"    
  app:aebMainButtonRotateDegree="0"    
  app:aebMainButtonSizeDp="50dp"    
  app:aebRippleEffect="true"    
  app:aebStartAngleDegree="270"    
  app:aebSubButtonSizeDp="50dp" />

2、初始化菜单

private void initSectorMenuButton() {    
  SectorMenuButton sectorMenuButton = (SectorMenuButton) findViewById(R.id.sector_menu);    
  final List<ButtonData> buttonDatas = new ArrayList<>();    
  int[] drawable = {R.mipmap.like, R.mipmap.mark, R.mipmap.search, R.mipmap.copy};    
  for (int i = 0; i < 4; i++) {        
    //最后一个参数表示padding
    ButtonData buttonData = ButtonData.buildIconButton(this, drawable[i], 0);            
    buttonData.setBackgroundColorId(this, R.color.colorAccent);        
    buttonDatas.add(buttonData);    
  }    
  sectorMenuButton.setButtonDatas(buttonDatas);    
  setListener(sectorMenuButton);
}

3、设置监听

private void setListener(final SectorMenuButton button) {    
  button.setButtonEventListener(new ButtonEventListener() {        
    @Override        
    public void onButtonClicked(int index) {            
      showToast("button" + index);        
    }        
    @Override        
    public void onExpand() {            
      showToast("onExpand");        
    }        
    @Override        
    public void onCollapse() {            
      showToast("onCollapse");        
    }    
  });
}

自定义属性说明

attribute value type 说明
aebStartAngleDegree integer 展开按钮的开始角度
aebEndAngleDegree integer 展开按钮的结束角度
aebMaskBackgroundColor color 当菜单为开启状态时全屏的背景颜色
aebIsSelectionMode boolean 当子按钮被选中,主按钮设置为选定状态
aebAnimDurationMillis integer 开启关闭菜单时播放动画的时间
aebMainButtonRotateAnimDurationMillis integer 主按钮旋转动画的时间
aebMainButtonRotateDegree integer 主按钮旋转动画的角度
aebButtonElevation dimen 按钮阴影效果的范围
aebRippleEffect boolean 当按钮单点击时是否设置水波纹效果
aebRippleColor color 主按钮点击时水波纹效果的颜色,默认为按钮颜色
aebMainButtonSizeDp dimen 主按钮的大小
aebMainButtonTextSizeSp dimen 主按钮的文字大小
aebMainButtonTextColor color 主按钮的文字颜色
aebSubButtonSizeDp dimen 子按钮的大小
aebSubButtonTextSizeSp dimen 子按钮的文字大小
aebSubButtonTextColor color 子按钮文字颜色
aebButtonGapDp dimen 主按钮与子按钮之间的距离

其它说明

因为当中用到了高斯模糊效果,代码如下

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@WorkerThread
private Bitmap getBlurBitmap(Context context, Bitmap inBitmap, float radius) {
  if (context == null || inBitmap == null) {
    throw new IllegalArgumentException("have not called setParams() before call execute()");
  }
  int width = Math.round(inBitmap.getWidth() * SCALE);
  int height = Math.round(inBitmap.getHeight() * SCALE);
  Bitmap in = Bitmap.createScaledBitmap(inBitmap, width, height, false);
  Bitmap out = Bitmap.createBitmap(in);
  RenderScript rs = RenderScript.create(context);
  ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs,Element.U8_4(rs));
  Allocation allocationIn = Allocation.createFromBitmap(rs, in);
  Allocation allocationOut = Allocation.createFromBitmap(rs, out);
  blurScript.setRadius(radius);
  blurScript.setInput(allocationIn);
  blurScript.forEach(allocationOut);
  allocationOut.copyTo(out);
  allocationIn.destroy();
  allocationOut.destroy();
  blurScript.destroy();
  rs.destroy();
  return out;
}

Android Studio中,support v8包不能通过添加dependencies的方式加入。从sdk的目录下手动拷贝到工程的libs下面。这个包的参考路径如下:sdk/build-tools/21.1.1/renderscript/lib/renderscript-v8.jar。
但是有个更简单的方法,只要在build.gradle中加入下面两句话即可直接使用RenderScript相关API:

defaultConfig { 
    ... 
    //start 
    renderscriptTargetApi 18 
    renderscriptSupportModeEnabled true 
    //end
 }

最后

最后给出github地址,给个star支持下作者。谢谢
https://github.com/Rance935/SectorMenu

本文作者:Rance935本文出处:Android 一个炫酷的扇形菜单转载请在开头注明作者详细信息和本文出处
欢迎关注我的微信公众号和QQ群,分享Android 开发和互联网内容
Android技术分享:群号534813930
微信号:androidparks
公众号:AndroidParks

评论

  • M88回复

    hello there and thank you for your info – I’ve certainly picked up anything new from right here. I did however expertise several technical issues using this website, since I experienced to reload the website a lot of times previous to I could get it to load correctly. I had been wondering if your web hosting is OK? Not that I am complaining, but sluggish loading instances times will very frequently affect your placement in google and can damage your quality score if ads and marketing with Adwords. Well I am adding this RSS to my e-mail and could look out for much more of your respective intriguing content. Make sure you update this again very soon..

  • find love回复

    I think other website proprietors should take this site as an model, very clean and magnificent user friendly style and design, as well as the content. You're an expert in this topic!

  • vitamins回复

    Normally I do not learn article on blogs, but I wish to say that this write-up very pressured me to check out and do so! Your writing taste has been surprised me. Thank you, quite nice post.

  • office gadgets回复

    I¡¦ll immediately grasp your rss as I can't find your e-mail subscription link or e-newsletter service. Do you've any? Please allow me recognise in order that I could subscribe. Thanks.

  • ground beef recipes回复

    Well I truly enjoyed studying it. This subject offered by you is very effective for accurate planning.

  • remodeling回复

    Of course, what a splendid website and informative posts, I will bookmark your site.Best Regards!

  • play games回复

    Wow, marvelous blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your site is excellent, as well as the content!

  • M88回复

    You can certainly see your skills within the paintings you write. The arena hopes for more passionate writers like you who are not afraid to mention how they believe. At all times follow your heart. "The point of quotations is that one can use another's words to be insulting." by Amanda Cross.

  • universalsitesupplies.co.uk回复

    I have been absent for a while, but now I remember why I used to love this site. Thank you, I will try and check back more frequently. How frequently you update your site?

  • universalsitesupplies.co.uk回复

    I genuinely enjoy looking at on this website , it contains great articles . "Violence commands both literature and life, and violence is always crude and distorted." by Ellen Glasgow.

  • universalsitesupplies.co.uk回复

    You are my inspiration, I own few blogs and infrequently run out from brand :). "Follow your inclinations with due regard to the policeman round the corner." by W. Somerset Maugham.

  • gold license回复

    Excellent, what a web site it is! This website presents helpful
    information to us, keep it up.

  • M88回复

    I have mastered some essential things through your blog post post. One other thing I would like to convey is that there are lots of games that you can buy which are designed specifically for preschool age small children. They incorporate pattern recognition, colors, animals, and designs. These typically focus on familiarization rather than memorization. This helps to keep children and kids occupied without having the experience like they are studying. Thanks

  • Tobias回复

    There are some interesting points in time in this article but I don’t know if I understood them all.

  • dog food回复

    Wonderful post but I was wondering if you could write a litte more on this subject? I'd be very thankful if you could elaborate a little bit more. Cheers!|

  • dog boarding回复

    I am continually invstigating online for ideas that can benefit me. Thank you!

  • Digital Technology回复

    Thanks , I've recently been looking for info about this topic for a while and yours is the best I've came upon so far. But, what concerning the conclusion? Are you sure about the supply?

  • Fastest Tehhnology回复

    I like the valuable info you provide in your articles. I will bookmark your weblog and check again here regularly. I'm quite sure I will learn many new stuff right here! Best of luck for the next!