炫酷:一句代码实现标题栏、导航栏滑动隐藏。ByeBurger库的使用和实现

其实上周五的时候已经发过一篇文章。基本实现了底部导航栏隐藏的效果。但是使用起来可能不是很实用。因为之前我实现的方式是继承了系统的导航栏,并且提供了响应的隐藏显示方法。这样就变相等于强制使用这个view,体验不是很好。所以抽时间把他优化了一下。因为改动比较大,所以重新写一下他的使用方法,当然作为改动补偿,我会在后半篇文章写出他的实现方式。

现在,ByeBuger可以轻易地将任何view在滑动的时候隐藏或者显示。同时支持头部(标题栏)和底部(导航栏)效果。

ByeBurger项目地址

先看一下全新的效果:

还不错吧。然而,实现这么炫酷的效果,仅仅需要一句代码!

使用

1.在gradle 编译库文件

2.你仅仅需要一句代码,对,没错,只需要在你的View上加入一句。
先使用CoordinatorLayout作为根布局,然后向你的任何View中插入一句app:layout_behavior属性,即可实现滑动的隐藏和显示。
你的标题栏可以是Toolbar或者LinearLayout或者什么鬼。
同样你的底部导航栏可以是最新的BottomNavigationView亦或者TabLayout在古老一点的RadioButton都可以!

具体的一句话是:

之后你就可以让你的app享受更多的阅读空间啦,相信这给用户带来了极大的便利。

注意

CoordinatorLayout类似于FrameLayout,所以注意xml层次,TitleBar和BottomTab要在xml下方。
只有实现NestScorll接口View的才可以实现监听,例如RecyclerView、NestScrollView.
在ListView下,是不生效的。

ByeBurger项目地址

以上就是ByeBurger的使用方式,接下来将会介绍ByeBurger的实现方式。如果你只是使用或者不感兴趣就不用往下看啦~~不过我还是建议你看一看,因为知道一个轮子的原理,百利无一害。

实现

0.改名原因

在ByeBurger 1.0版本的时候,其实ByeBurger不叫ByeBurger的,而叫做ByeBurgerNavigationView, 由名字可以看出,他是扩展了系统的BottomNavigationView,可是这样做有许多弊端,比如强制用户使用了某个控件,这样通用性不强。第二,为了用户有更多的选择,加入了头部隐藏效果。所以说,这个项目已经不能被称为NavigationView。于是我将名称进行了修改。

1.历史实现

在1.0版本,我继承了BottomNavigationView。提供了两个方法,一个是show,另一个是hide.

实际上就是对Y坐标进行了一些处理。给个动画再让他改变他的Y坐标。来达到隐藏效果。(总之隐藏就是让用户看不到)

然后利用Behavior,对NestScroll相关滑动进行监听,来改变ByeBurgerNavigationView的状态。

当然,这是1.0的实现,实用性比较低。所以有了1.1.0版本。

2.更新实现

整体思路就是利用自定义behavior去监听nestScroll的滑动,来让对应的View改变。之前在CoordinatorLayout 自定义Behavior并不难,由简到难手把手带你撸三款! 中介绍过一种Behavior的使用方式,不熟悉的可以先过去看看。这里用到的是第二种,主要是针对NestScroll进行监听。

首先,要自定义一个Behavior,他的泛型,也就是child view为View。 这也保证了它的通用性。

其次来处理一下onStartNestedScroll()方法,他提供一个返回值,用于过滤掉滑动事件。这里我们只关心上下滑动。所以应该这样。

最后,在onNestedPreScroll()进行child的对应操作。首先要根据参数dy来判断上下滑动,然后再根据view当前的状态来显示或者隐藏目标View。

在上面函数里,view的隐藏和显示委托给了AnimateHelper类。这是一个Helper,用来管理View的状态,也就是托付View隐藏或者显示。他的代码很简单,如下:

提供一些成员,用于保存 状态,模式,起始Y坐标等等。

提供一个工厂方法,用于获得处理目标view的helper:

之后,提供show方法和hide方法,用于执行view的隐藏或者显示:

而 showTitle()和 showBottom()之类的如1.0版一样,是改变了一下y坐标,然后执行动画。

如何让用户使用

这里参考了系统预留behavior的使用方式,由于Behavior实例是系统反射出来的,所以需要完整的包名。于是我就将Beavior的包名写在了string.xml里,如下:

所以用户使用起来及其简便,只需要在xml中给view加入一行代码app:layoutbehavior=”@string/byeburgerbottom_behavior”即可。

以上,ByeBurger库的使用和实现就写完了。终于有机会回馈开源社区了,我感到很开心,哇咔咔。

如果你觉得还不错 欢迎star, 更欢迎贡献代码。

本库下载地址:https://github.com/githubwing/ByeBurger

欢迎加入我的android群:425983695

炫酷:一句代码实现标题栏、导航栏滑动隐藏。ByeBurger库的使用和实现》有31个想法

  1. Do you feel like you have tried everything possible in order to lose weight? You are not alone–many people have the same problem. The following article is designed to give you tips that you may not have even known existed. By following these tips, you will reach your weight loss goal in no time.

  2. If your partner complains that you snore during your sleep, or if you wake up in the morning feeling tired and grouchy, you may have a common sleep disorder called sleep apnea. This means that at night, your airway is blocked and you stop breathing during your sleep. If you have this condition, you need to find treatment right away to avoid further problems.

    Strengthen your throat and jaw with some basic exercises. Developing these muscles should reduce the symptoms of sleep apnea. You can exercise your throat and jaw by simply pulling your tongue or practicing some very simple breathing exercises. The goal is to train you to breathe differently and hopefully make your sleep apnea disappear.

    If you have just been diagnosed with sleep apnea and prescribed a CPAP, join a CPAP support group. It can be quite difficult to get used to sleeping with a mask on your face every night. Sitting in a room full of other people going through the same thing can be very empowering. You can learn from others who have had the same issues you are having and made adjustments to make it work.

    If you suffer from sleep apnea, it is vital to avoid consuming alcohol before bedtime. Alcohol acts as a sedative, therefore, it will naturally slow down your breathing. In addition, it will relax all the muscles in your body, including those in your throat that help to keep your airway open.

    Try your best to lay off tobacco and nicotine products. Cigarette smoke can irritate your upper airway causing it to swell up, subsequently hindering your ability to breath during the night. Quitting smoking could therefore, significantly improve your sleep apnea symptoms and will also improve your body’s overall health and your feelings of well-being.

    To help diagnose your sleep apnea, your doctor may ask you to keep a sleep log. This log is where you’ll keep track of how much you sleep during the night, and other symptoms you may experience. Your partner can let you know if you snore too loudly, jerk your limbs, or stop breathing. Your doctor will then be able to tell if you suffer from sleep apnea.

    Avoid any type of drugs or alcohol if you are experiencing any type of sleep apnea. Drugs and alcohol will slow down your respiratory system, and that is known to be one of the causes of sleep apnea. If you are struggling with this issue, try to get some professional help to overcome these addictions.

    Drink one cup of caffeinated coffee a few hours before you go to sleep. It may seem silly to drink a caffeine drink at night, but this can actually help keep your throat open while you sleep. You may have to play around with what time you drink the coffee to avoid restlessness.

    If simple changes in your lifestyle, such as regular sleep hours and losing weight, have not eliminated your sleep apnea episodes, it is time to consult with a sleep specialist. The specific causes of your sleep apnea can be evaluated, and an individual treatment plan can be designed for you.

    By reading through the great sleep apnea tips found in this article, you are ready to face your problem head on. While you may not be able to rid yourself of the problem completely, you will feel more confident and start working towards that all-important goal, a good night’s sleep.

    viagrasansordonnancefr.com

  3. fotbollströjor \n Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way fotbollstrojor sverigen , how could we communicate?|

  4. [url=http://www.malluz.com/blogs/post/6574]www.malluz.com[/url] [url=http://www.malluz.com/blogs/post/6275]www.malluz.com[/url] [url=http://www.myindiagate.com/community/groups/130554]www.myindiagate.com[/url] [url=http://francesc.blogrip.com/2017/03/22/barcelona-troja-som-spelade-i-libanon-s-premier-league/]francesc.blogrip.com[/url]

  5. I simply wanted to say thanks once more. I am not sure the things I would have sorted out without the tricks provided by you over my concern. It actually was the depressing concern for me personally, nevertheless coming across a new expert tactic you managed that forced me to jump for delight. Extremely thankful for this support and in addition hope that you recognize what an amazing job you are carrying out instructing many people all through your websites. I know that you have never got to know all of us.

  6. I definitely wanted to post a simple message to be able to thank you for the fabulous techniques you are showing at this site. My incredibly long internet research has finally been recognized with good quality information to exchange with my best friends. I ‘d express that many of us site visitors actually are very much endowed to live in a great website with many awesome individuals with very beneficial secrets. I feel quite fortunate to have discovered your entire website and look forward to many more awesome times reading here. Thank you once again for a lot of things.

  7. I simply had to appreciate you once again. I do not know what I might have worked on in the absence of the type of tips and hints provided by you directly on my situation. It was actually a real intimidating setting for me, but viewing this professional manner you solved it made me to jump over gladness. Extremely happy for your support and in addition sincerely hope you know what a great job you have been providing teaching others via your websites. I’m certain you haven’t got to know any of us.

  8. I would like to voice my admiration for your kindness supporting women who really need help with the niche. Your real dedication to passing the solution throughout ended up being astonishingly insightful and have constantly made men and women much like me to get to their dreams. Your own helpful guidelines denotes so much a person like me and additionally to my office workers. Many thanks; from each one of us.

  9. Thank you for all your efforts on this blog. My mom really loves carrying out investigations and it is easy to see why. Almost all know all about the powerful mode you make very useful tips and tricks by means of the web blog and even welcome participation from others about this area then my daughter is without question being taught a lot of things. Enjoy the remaining portion of the year. You have been doing a pretty cool job.

  10. Needed to post you that little note so as to say thanks yet again considering the awesome concepts you’ve documented in this article. It was certainly seriously open-handed with people like you to grant openly all a number of us would’ve supplied for an e book in order to make some profit on their own, particularly now that you might have done it in the event you wanted. These guidelines in addition acted to become good way to be sure that someone else have a similar desire much like my very own to see somewhat more with regards to this issue. I’m sure there are a lot more enjoyable sessions ahead for individuals that scan your website.

  11. I together with my pals were found to be examining the best information and facts from the website while at once came up with a terrible suspicion I had not thanked you for those tips. These boys are actually for that reason happy to read through them and have now unquestionably been having fun with those things. Thanks for being well considerate and then for going for some incredible guides most people are really desirous to be aware of. My sincere apologies for not expressing appreciation to sooner.

  12. Thanks so much for providing individuals with an exceptionally wonderful possiblity to check tips from here. It’s usually very awesome plus stuffed with a great time for me and my office fellow workers to visit the blog at minimum three times per week to read the new guides you will have. Of course, I’m actually fascinated for the gorgeous pointers served by you. Selected 4 tips in this post are easily the best I’ve had.

  13. I actually wanted to type a message so as to appreciate you for some of the marvelous pointers you are writing at this site. My incredibly long internet search has at the end of the day been compensated with beneficial tips to share with my friends and classmates. I ‘d assume that most of us site visitors are undoubtedly fortunate to dwell in a magnificent community with very many perfect people with great points. I feel pretty fortunate to have used your entire site and look forward to tons of more thrilling moments reading here. Thanks a lot again for a lot of things.

  14. I simply needed to thank you so much once more. I do not know the things I would have taken care of without the type of tactics provided by you concerning such subject. It actually was a real fearsome scenario in my position, however , considering the very expert avenue you processed it took me to cry over delight. I will be thankful for the work and then sincerely hope you are aware of an amazing job that you’re providing educating some other people by way of your webpage. Most likely you haven’t encountered all of us.

  15. I’m just writing to make you know what a really good experience my girl went through visiting the blog. She even learned plenty of pieces, which included what it is like to have an ideal teaching mindset to let other folks with no trouble completely grasp various tortuous matters. You truly did more than people’s desires. I appreciate you for supplying these interesting, dependable, educational and cool tips about this topic to Mary.

  16. Thank you so much for providing individuals with remarkably marvellous opportunity to check tips from this blog. It can be so pleasant plus stuffed with fun for me and my office friends to visit your website no less than 3 times a week to find out the fresh secrets you have got. And definitely, I’m actually fulfilled with all the dazzling things served by you. Certain 3 facts on this page are undeniably the most beneficial I have had.

  17. I enjoy you because of all of your efforts on this web page. Kim loves doing investigations and it is obvious why. Many of us know all of the compelling tactic you render both interesting and useful tips and hints through this web site and even recommend contribution from others about this matter and our own daughter is really discovering a great deal. Enjoy the remaining portion of the new year. You’re carrying out a very good job.

  18. I want to express my appreciation to you for rescuing me from this type of circumstance. Because of surfing around throughout the search engines and seeing opinions which were not productive, I believed my life was well over. Living without the strategies to the issues you’ve sorted out by way of the guide is a critical case, and the ones which could have adversely affected my career if I had not encountered the website. Your own personal mastery and kindness in dealing with every aspect was helpful. I don’t know what I would’ve done if I had not come across such a solution like this. I am able to now look forward to my future. Thanks for your time so much for this impressive and amazing guide. I will not think twice to refer the blog to anyone who would like support about this topic.

  19. I in addition to my friends were found to be looking through the best guidelines located on your web site and so then I got a horrible feeling I had not thanked the website owner for those techniques. All the ladies were for this reason happy to read through all of them and now have surely been loving those things. Appreciate your simply being so accommodating and also for making a decision on some fine subjects most people are really desperate to discover. Our sincere regret for not saying thanks to sooner.

  20. I and my guys were found to be digesting the great information and facts located on the blog then unexpectedly I got an awful feeling I never expressed respect to the web site owner for those strategies. Most of the guys are actually as a result passionate to study them and have pretty much been making the most of these things. We appreciate you simply being considerably thoughtful and for picking some fantastic subject areas most people are really wanting to be informed on. My very own honest apologies for not saying thanks to sooner.

  21. I needed to send you one little remark so as to thank you over again regarding the lovely suggestions you have provided on this site. It is quite tremendously generous of you to deliver easily exactly what some people could possibly have distributed for an e-book to help make some profit on their own, precisely seeing that you might well have tried it if you ever wanted. The ideas likewise acted to be the fantastic way to recognize that someone else have the identical zeal just as my personal own to see much more pertaining to this problem. I’m sure there are many more pleasurable moments in the future for individuals that go through your site.

  22. Job helps Australia have a very great status in the Australia for your assignment help providers. The simplest way to judge the publishing skills and also the syntax of the student could be the dissertation writing assignments. So to help the pupils using their article writing job help Australia start the company. Composition writing is of several types it change from the analysis themes to the industry of passions therefore to preserve this part of mind project help Sydney retain a skilled specialists authors which help the students with their dissertation work support. If you want A+ quality inside the exams you’re a press away from the excellent support of job help. Authors of regulations dissertation writing service focus on offer outstanding law essay writing assistance.
    custom essay

  23. I precisely wished to appreciate you all over again. I’m not certain what I could possibly have handled in the absence of the entire aspects shown by you relating to such topic. Entirely was an absolute troublesome condition for me personally, but viewing the specialized tactic you dealt with that took me to cry with happiness. I am happy for the assistance and pray you realize what an amazing job your are carrying out teaching the rest through the use of your websites. Most likely you haven’t encountered any of us.

  24. I am commenting to make you know of the superb encounter my daughter undergone viewing the blog. She discovered too many issues, which included how it is like to possess an incredible helping nature to get many more without problems know just exactly various tricky topics. You actually surpassed visitors’ expected results. Thanks for producing the invaluable, trustworthy, informative and cool tips on the topic to Evelyn.

  25. I’m writing to make you know of the great experience my daughter encountered visiting yuor web blog. She came to understand such a lot of issues, most notably how it is like to have a wonderful helping mindset to get many others just master selected multifaceted subject areas. You undoubtedly exceeded my desires. Thanks for offering those powerful, trusted, revealing and easy tips about the topic to Gloria.

  26. I actually wanted to send a brief note in order to appreciate you for those magnificent hints you are sharing at this site. My particularly long internet look up has at the end been honored with extremely good facts and strategies to go over with my two friends. I would say that most of us site visitors actually are very blessed to exist in a fine website with so many brilliant individuals with helpful advice. I feel rather blessed to have discovered your entire website page and look forward to many more exciting minutes reading here. Thanks once again for everything.

发表评论

电子邮件地址不会被公开。