Android翻页效果加苹果桌面应用抖动效果

效果预览

这是最近项目的一个需求,作者写这篇文章目的不是想教大家如何做这个动画。很多动画很多效果,都有开源作者已经实现了,我们只需要拿来用。在实际开发中开发效率才是第一步,源码的学习可以放在自己没事的时候来做。分享下我拿到一个需求时是怎样一步一步来攻克的。个人见解,不吝赐教!

分析

首先我们先将动画分解,这一动画分为两部分
- 翻页动画
- item抖动效果

然后我们再来看布局,可能一开始拿到这个效果图,我们直接就认为笔记本里面就是一个gridview或者一个横向的recyclerview。其实不然,我们认真分析可以看出不管是gridview还是横向recyclerview,它们的item第一行从左往右都是item0、item1、item2、item3,而我们实现的效果是笔记本的左边页->右边页,也就是必须要左边半页填满后才向右边半页填数据,作者用了两个两行两列的girdview放在笔记本里面,实现了这一效果。如下图(注意看item的下标):

编码实现

翻页效果

如果我们自己来写这个翻页的效果,还是有点复杂。经过搜索我发现了一个类库android-FlipView已经实现了这一效果,在这里也感谢原作者的贡献。android-FlipView支持左右翻页和上下翻页。
作者将api设计得尽可能跟ListView一样。FlipView拥有一个一般的adapter,你可以在如下设置adapter:

void setAdapter(ListAdapter adapter);
ListAdapter getAdapter();

获取可翻转的页数和当前页:

int getPageCount();
int getCurrentPage();

类似于ListView中scrollTo, smoothScrollTo, scrollBy 和smoothScrollBy 作用的一些方法:

void flipTo(int page);
void smoothFlipTo(int page);
void flipBy(int pageDelta);
void smoothFlipBy(int pageDelta);

翻页效果最大的难题已经解决,接下来问题就是数据封装,嵌套两个girdview了,这里简单贴下代码,感兴趣的可以直接去看源码。

/**
         * 当前数据8个一页,获取总页数
         * 两种情况1:数据长度刚好是8的倍数,那么总页数=数据长度÷8
         *        2:数据长度不为8的倍数,总页数=数据长度÷8 + 1 (为什么加1?因为长度与8相除有余数,余数这一部分也要占一页)
         */
        if (familyInfos.size() % 8 == 0) {
            totalPage = familyInfos.size() / 8;
        } else {
            totalPage = familyInfos.size() / 8 + 1;
        }

        /**用一个新的集合来装每一页里面的数据,形成一个新的集合
         * 循环总页数次   用List.subList(int start, int end)方式取出数据  注意这里的参数不是下标,从1开始
         * 同样两种情况1:当当前页的数据刚好8个的时候直接取
         *            2:最后一页的情况,就是从 页码*8->数据长度
         */
        List<List<FamilyInfo>> family = new ArrayList<>();
        for (int i = 0; i < totalPage; i++) {
            List newlist = null;
            if (i * 8 + 7 < familyInfos.size() - 1) {
                newlist = familyInfos.subList(i * 8, (i + 1) * 8);
            } else {
                newlist = familyInfos.subList(i * 8, familyInfos.size());
            }
            family.add(newlist);
        }
        adapter = new FlipViewAdapter(this, family);
        flipView.setAdapter(adapter);

抖动效果

开始作者用的是gridview的setLayoutAnimation方法,不了解LayoutAnimation的可以去搜索下,但是这种方式只能在girdview第一次加载的时候才会有,后面我们再需要开启动画就不行了。
所以只有一个item一个item的去做动画了。分析一下这个动画,这个抖动的动画是以item的中心点左右旋转。ok,那就用rotate旋转动画

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="100"
    android:fromDegrees="-2"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toDegrees="2" />
<!--    
  duration      动画执行时间
  fromDegrees   动画开始时的角度   
  toDegrees     动画结束时物件的旋转角度,正代表顺时针     
  pivotX    属性为动画相对于物件的X坐标的开始位置  
  pivotY    属性为动画相对于物件的Y坐标的开始位置
  repeatCount 动画的重复次数 infinite表示循环
  repeatMode  重复模式  restart:重新从头开始执行。reverse:反方向执行。
-->   

总结

以上只是一个大概的思路,感兴趣的可以去我的github看下源码。重点说明,因为是在平板上面做的,没有做适配。可以用模拟器看效果或者横屏模式。

本文作者:Rance935本文出处:Android翻页效果加苹果桌面应用抖动效果转载请在开头注明作者详细信息和本文出处
欢迎关注我的微信公众号和QQ群,分享Android 开发和互联网内容
Android技术分享:群号534813930
微信号:androidparks
公众号:AndroidParks

评论

  • mirtazapines.stream回复

    It's genuinely very complicated in this active life to
    listen news on Television, so I just use the web for that reason, and get the newest news.

  • other回复

    I simply want to mention I am just very new to weblog and actually liked your web page. Almost certainly I’m going to bookmark your website . You actually come with very good writings. Many thanks for sharing with us your webpage.

  • order orlistat online回复

    What you posted made a ton of sense. However, what about this?
    what if you were to write a awesome post title? I mean, I
    don't want to tell you how to run your website, but suppose you added a headline that makes people desire more?
    I mean Android翻页效果加苹果桌面应用抖动效果 - Rance935 is
    a little boring. You ought to look at Yahoo's home page and see how they write news headlines to grab people to open the links.
    You might add a related video or a pic or two to grab readers interested about
    everything've got to say. Just my opinion, it would bring your posts a
    little livelier.

  • Luiz Gastão Bittencourt da Silva回复

    I’m not that much of a internet reader to be honest but your sites really nice, keep it up! I'll go ahead and bookmark your website to come back later. Cheers|

  • buy cialis online回复

    buy cialis online canadian pharmacy
    buy cialis online
    order cialis online prescription

  • pink finger vibrator回复

    although internet sites we backlink to beneath are considerably not associated to ours, we feel they may be actually worth a go through, so possess a look

  • Penumbuh brewok回复

    I always emailed this webpage post page to all
    my contacts, as if like to read it afterward my friends will too.

  • rainbow bongs回复

    Hi to every single one, it's in fact a pleasant for me to go to see this web page, it consists
    of useful Information.

  • my link回复

    I simply want to tell you that I'm beginner to weblog and seriously enjoyed this website. More than likely I’m going to bookmark your blog post . You absolutely have fabulous article content. Thanks a lot for revealing your web site.

  • video strategist回复

    This design is steller! You definitely know how to keep a reader amused.
    Between your wit and your videos, I was almost moved to start my
    own blog (well, almost...HaHa!) Great job. I really
    loved what you had to say, and more than that, how you presented
    it. Too cool!

  • Rifan Financindo回复

    +Thomas Cooper The ones we had over the course of the 28
    years I spent in the market were corrections, not crashes.
    I mean the financial equivalent of a Carrington Event, a true financial tsunami.
    We haven't had the Big One. Yet.

  • Continued回复

    I just want to mention I'm all new to weblog and truly enjoyed you're page. More than likely I’m likely to bookmark your blog post . You definitely come with really good articles and reviews. Regards for sharing your webpage.

  • new rabbit vibrator回复

    check beneath, are some completely unrelated web sites to ours, having said that, they may be most trustworthy sources that we use

  • Luiz Gastão Bittencourt回复

    You ought to take part in a contest for one of the greatest sites on the net. I most certainly will recommend this blog!|

  • nhl jerseys回复

    I discovered your weblog website on google and test just a few of your early posts. Continue to keep up the superb operate. I just further up your RSS feed to my MSN Information Reader. Looking for ahead to reading more from you in a while!?

  • the 4 week bikini diet回复

    If some one wants expert view about blogging and site-building then i suggest him/her to visit
    this weblog, Keep up the pleasant work.

  • content回复

    I just want to say I'm new to weblog and truly loved this website. Very likely I’m likely to bookmark your blog post . You absolutely have really good articles. Thanks a bunch for sharing your web-site.

  • 4 week energy diet recipes回复

    What's up to every body, it's my first visit of this blog;
    this blog carries amazing and genuinely good material in favor of visitors.

  • ultra boost 3.0回复

    I intended to draft you the little word just to give thanks yet again considering the fantastic basics you've provided on this site. This has been quite strangely generous of people like you giving unhampered precisely what most people might have distributed for an ebook to make some money on their own, particularly now that you might well have tried it in case you decided. These thoughts likewise served to provide a great way to be aware that other people have a similar interest much like my own to learn way more concerning this problem. I think there are numerous more fun periods ahead for those who scan your website.

  • Get More Information回复

    I simply want to say I am very new to blogging and truly enjoyed your website. More than likely I’m planning to bookmark your blog post . You definitely come with exceptional articles. Thanks a lot for sharing with us your web page.

  • 4 week energy diet ebook回复

    Hi there i am kavin, its my first occasion to commenting anywhere, when i read this piece of writing i thought i could also make comment due to this brilliant paragraph.

  • 4 week energy diet ebook回复

    Have you ever thought about writing an ebook or guest authoring
    on other sites? I have a blog based upon on the
    same subjects you discuss and would really like to have you share some stories/information. I know my subscribers would value
    your work. If you are even remotely interested, feel free to send me an e mail.

  • adidas官網回复

    Here is a superb Weblog You might Come across Intriguing that we Encourage You

  • best boat parties marbella回复

    Hi there, I found your blog by way of Google even as searching
    for a similar topic, your website got here up, it appears to be
    like great. I have bookmarked it in my google bookmarks.
    Hello there, simply was aware of your weblog via Google, and found that it's really informative.

    I'm gonna be careful for brussels. I will appreciate if you continue this
    in future. Many people shall be benefited out of your writing.
    Cheers!

  • i thought about this回复

    I simply want to say I am just new to blogs and really enjoyed this web site. Almost certainly I’m planning to bookmark your site . You amazingly have perfect writings. Kudos for sharing your blog.

  • look at here now回复

    I simply want to say I'm newbie to weblog and actually enjoyed your web site. Almost certainly I’m likely to bookmark your blog . You absolutely come with good articles. Thanks a lot for sharing with us your blog.

  • แปรงใส่ปลอกท้าย回复

    Woah! I'm really enjoying the template/theme of this site.
    It's simple, yet effective. A lot of times it's hard
    to get that "perfect balance" between usability and visual appeal.
    I must say you have done a very good job with this.

    In addition, the blog loads super fast for me on Chrome.
    Excellent Blog!

  • แปรงลวดสแตนเลส回复

    I'm pretty pleased to uncover this web site. I need to to thank you for your time for this particularly wonderful read!!
    I definitely really liked every little bit of it and i also
    have you saved to fav to see new things in your blog.

  • Lelio Vieira Carneiro回复

    I blog quite often and I seriously thank you for your content. Your article has truly peaked my interest. I will bookmark your blog and keep checking for new information about once per week. I subscribed to your Feed as well.|

  • More Help回复

    I just want to mention I'm beginner to blogging and site-building and seriously liked this website. Almost certainly I’m planning to bookmark your site . You absolutely have incredible stories. Kudos for revealing your blog site.

  • why not find out more回复

    I just want to mention I am just newbie to blogs and truly enjoyed this blog. Very likely I’m want to bookmark your blog post . You certainly come with remarkable stories. Kudos for sharing with us your website page.

  • best site回复

    I just want to mention I am very new to blogging and site-building and really enjoyed you're blog. Likely I’m going to bookmark your blog post . You definitely have perfect articles. Thanks a lot for revealing your web page.

  • check my site回复

    I just want to mention I am just beginner to blogging and site-building and definitely savored your page. Likely I’m going to bookmark your site . You absolutely have terrific articles. Regards for sharing your webpage.

  • visit site回复

    I simply want to tell you that I am beginner to weblog and truly liked this website. Most likely I’m planning to bookmark your website . You actually come with great well written articles. Kudos for sharing your blog site.

  • read more回复

    I just want to say I'm beginner to weblog and really loved your page. More than likely I’m want to bookmark your blog . You amazingly come with superb articles and reviews. Regards for sharing your web site.

  • programming回复

    always a massive fan of linking to bloggers that I like but really don't get a whole lot of link really like from

  • Itamar Serp回复

    I was suggested this website by my cousin. I am no longer positive whether this post is written by him as nobody else realize such certain about my problem. You are incredible! Thank you!|

  • my link回复

    I just want to mention I am just very new to weblog and absolutely enjoyed your web blog. Most likely I’m going to bookmark your website . You surely have outstanding articles and reviews. Thanks a bunch for sharing your webpage.

  • best site回复

    I just want to mention I am just newbie to blogging and seriously liked you're web-site. Almost certainly I’m going to bookmark your blog . You amazingly come with perfect posts. Bless you for sharing with us your website page.

  • adidas ultra boost 3.0回复

    I discovered your weblog website on google and examine a couple of of your early posts. Proceed to maintain up the excellent operate. I simply further up your RSS feed to my MSN News Reader. Searching for ahead to studying more from you in a while!?

  • yeezy shoes回复

    I and my friends have already been taking note of the best ideas located on your web site and all of the sudden I had a horrible feeling I never thanked the website owner for those tips. These boys came as a result happy to learn them and have unquestionably been taking advantage of them. We appreciate you being well kind and then for utilizing certain helpful useful guides most people are really eager to discover. My sincere regret for not expressing gratitude to you earlier.

  • Pull Up Queen回复

    Somebody necessarily lend a hand to make severely articles I might state.
    That is the very first time I frequented your website page and up to now?
    I surprised with the analysis you made to create this actual publish incredible.
    Great process!

  • Rene回复

    No matter if some one searches for his vital thing, thus he/she wants to be available that in detail, therefore
    that thing is maintained over here.

  • CHIROPRATICO ROMA回复

    I don't know if it's just me or if perhaps everyone else encountering issues
    with your website. It seems like some of the text within your posts are running off the
    screen. Can somebody else please comment and let me know if this is happening to them too?
    This could be a issue with my browser because I've had
    this happen before. Appreciate it

  • tinder dating回复

    Hello every one, here every person is sharing these kinds of familiarity, therefore it's pleasant to
    read this website, and I used to pay a visit this web site all
    the time.

  • vibrating didlos回复

    Here is a great Weblog You might Uncover Interesting that we Encourage You