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

评论

  • VladilenGergo回复

    cialis levitra contre viagra

    [url=http://viagraomz.com/]buy generic viagra[/url]

    <a href="http://viagraomz.com/">buy generic viagra</a>

    afghanistan viagra post

  • CheplanovaGergo回复

    herb viagra 6800mg review

    [url=http://viagralms.com/]viagra online[/url]

    <a href="http://viagralms.com/">buy generic viagra</a>

    blue pill generic viagra

  • arts media回复

    hello there and thank you for your information – I’ve definitely picked up something new from right here. I did however expertise several technical issues using this site, as I experienced to reload the site lots of times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and can damage your high-quality score if ads and marketing with Adwords. Anyway I’m adding this RSS to my e-mail and can look out for much more of your respective intriguing content. Make sure you update this again soon..

  • School Of Science回复

    As a Newbie, I am permanently searching online for articles that can be of assistance to me. Thank you

  • Cabinets回复

    hi!,I really like your writing so much! proportion we keep up a correspondence extra approximately your post on AOL? I need an expert in this area to unravel my problem. May be that's you! Taking a look ahead to look you.

  • monumentaal-ontwerper.nl回复

    Very nice post. I just stumbled upon your blog and wished
    to say that I have truly enjoyed browsing your blog posts.
    In any case I will be subscribing to your rss
    feed and I hope you write again very soon!

  • Luiz Gastão Bittencourt回复

    Excellent website you have here but I was curious if you knew of any community forums that cover the same topics discussed in this article? I'd really like to be a part of group where I can get responses from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Cheers!|

  • yeezy回复

    I wanted to draft you this little bit of observation to say thank you as before for these splendid solutions you've shared above. This has been quite extremely open-handed of you to make openly all that a lot of people would've offered for an e book to earn some dough for themselves, specifically considering the fact that you could possibly have tried it if you considered necessary. The tricks also served as the easy way to fully grasp some people have the same keenness really like mine to know a little more with regards to this matter. I am sure there are a lot more enjoyable opportunities ahead for those who looked at your blog.

  • memek sobek回复

    Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku
    cuman satu Memek ku cuman satu Memek ku cuman satu
    Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu
    Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek
    ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku
    cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu
    Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek
    ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek
    ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek
    ku cuman satu Memek ku cuman satu Memek ku cuman satu
    Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu
    Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu
    Memek ku cuman satu Memek ku cuman satu Memek ku cuman satu

  • kelleher international reviews回复

    Excellent beat ! I wish to apprentice while
    you amend your site, how can i subscribe for a blog web site?
    The account aided me a acceptable deal. I had been a little bit acquainted
    of this your broadcast provided bright clear idea

  • michael kors handbags回复

    Oh my goodness! an amazing article dude. Thank you Nonetheless I'm experiencing issue with ur rss . Don抰 know why Unable to subscribe to it. Is there anybody getting similar rss problem? Anybody who knows kindly respond. Thnkx

  • CheplanovaGergo回复

    viagra en ligne gratuit

    [url=http://viagralms.com/]buy viagra[/url]

    <a href="http://viagralms.com/">buy viagra online</a>

    buy us viagra

  • Umanizzare presídios回复

    I was very happy to discover this great site. I wanted to thank you for ones time for this wonderful read!! I definitely really liked every little bit of it and i also have you bookmarked to see new things on your site.|

  • read me回复

    Hi there! Would you mind if I share your blog with my twitter group?
    There's a lot of folks that I think would really enjoy your content.
    Please let me know. Many thanks

  • Law回复

    I've been surfing online more than three hours lately, but I by no means discovered any interesting article like yours. It is pretty worth sufficient for me. Personally, if all site owners and bloggers made good content as you probably did, the net can be much more useful than ever before.

  • Gardenia回复

    Hello my friend! I want to say that this post is amazing, great written and come with almost all vital infos. I would like to look extra posts like this .

  • Educator回复

    As I web-site possessor I believe the content material here is rattling magnificent , appreciate it for your hard work. You should keep it up forever! Good Luck.

  • culinary回复

    I have to show my thanks to this writer just for bailing me out of this particular problem. Just after researching through the search engines and meeting techniques which were not pleasant, I was thinking my entire life was done. Existing without the approaches to the issues you've solved by means of your main website is a crucial case, as well as ones which might have in a wrong way damaged my entire career if I hadn't encountered your web page. Your own know-how and kindness in maneuvering a lot of things was precious. I am not sure what I would have done if I hadn't come across such a step like this. I can also at this moment look forward to my future. Thank you so much for the skilled and sensible help. I won't hesitate to endorse the website to any person who requires guidance about this subject.

  • House回复

    Fantastic beat ! I would like to apprentice while you amend your web site, how can i subscribe for a blog site? The account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear idea

  • lanyard回复

    I want to to thank you for this fantastic read!! I definitely
    loved every bit of it. I have got you book-marked to check out new stuff you post…

  • http://bit.ly/2zfhjY6回复

    Fascinating bloց! Is your theme custom made or did
    you download it from somewhere? A deѕign like youгs with a feew
    simple tweeks would really mɑkе my blog jᥙnp out.
    Please let me know wheгe you got yor theme.
    Thank yօu

  • sup vi ca回复

    I appreciate, cause I discovered exactly what I used to be looking for.
    You have ended my 4 day long hunt! God Bless you man. Have a
    nice day. Bye