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

评论

  • Umanizzare Gestão Prisional Ltda回复

    Its like you read my mind! You appear to grasp a lot about this, like you wrote the ebook in it or something. I believe that you just can do with some p.c. to force the message home a little bit, but instead of that, this is wonderful blog. A great read. I will certainly be back.|

  • orzen回复

    I'm not certain the place you are getting your information, however great topic.

    I must spend some time finding out much more or working out more.
    Thank you for excellent information I was looking for this information for my mission.

  • burung kenari回复

    Thanks a lot for sharing this with all people you actually
    recognize what you are talking approximately! Bookmarked.
    Please additionally discuss with my site =). We may have a hyperlink alternate contract among us

  • หวยออนไลน์回复

    What's up it's me, I am also visiting this website daily, this website is really pleasant and the viewers are
    genuinely sharing fastidious thoughts.

  • CheplanovaGergo回复

    viagra lieferung osterreich

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

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

    spanish viagra

  • หวยออนไลน์回复

    I am no longer sure the place you are getting your info, but
    good topic. I needs to spend a while studying more or understanding more.
    Thanks for excellent info I used to be looking for this information for my mission.

  • Grupo Coral presidios回复

    Please let me know if you're looking for a article writer for your site. You have some really good articles and I believe I would be a good asset. If you ever want to take some of the load off, I'd love to write some articles for your blog in exchange for a link back to mine. Please shoot me an e-mail if interested. Kudos!|

  • Streaming Jav Online Free回复

    Its like you read my mind! You seem to know a lot approximately
    this, such as you wrote the book in it or something.
    I believe that you simply can do with a few p.c.
    to drive the message house a bit, but instead of that, that is magnificent blog.
    An excellent read. I will certainly be back.

  • yeezy回复

    My wife and i were contented when John could carry out his survey using the ideas he got through the web page. It's not at all simplistic just to possibly be giving out information and facts which often men and women might have been selling. We really fully understand we have the blog owner to thank for that. Most of the illustrations you made, the simple site navigation, the friendships you can aid to create - it's got most overwhelming, and it's letting our son in addition to our family reason why the subject is exciting, which is exceptionally essential. Thanks for all the pieces!

  • myrssreade回复

    Why people still make use of to read news papers when in this technological globe everything is available on web?

  • Delhi-dolls回复

    Wow, incredible blog format! How lengthy have you been running a blog for? you made blogging look easy. The overall look of your site is wonderful, let alone the content!

  • Legal Aid Society回复

    Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how could we communicate?

  • anal sex trainer kit回复

    very handful of sites that take place to become detailed beneath, from our point of view are undoubtedly very well really worth checking out

  • robot gap gach回复

    Does your site have a contact page? I'm
    having problems locating it but, I'd like to shoot you an e-mail.

    I've got some ideas for your blog you might be interested in hearing.
    Either way, great website and I look forward to seeing it expand over time.

  • Luiz Gastão Bittencourt回复

    I got this web page from my friend who shared with me concerning this web page and now this time I am visiting this web page and reading very informative content at this time.|

  • Answering surveys online for money回复

    I relish, result in I found just what I used to be taking
    a look for. You have ended my 4 day lengthy hunt!
    God Bless you man. Have a nice day. Bye

  • naprawa pralek wroclaw tanio回复

    Yoᥙ really make it seem so easy ѡith your pгesentatіon but
    I find this matter to be actuaⅼly something that I think I would never understand.
    It seems too complex and extremeⅼy broad for me.
    I'm lߋoking forward for your next post, I ᴡill try
    to get the hang ⲟf it!

  • Buy Vigra回复

    check beneath, are some entirely unrelated web-sites to ours, on the other hand, they may be most trustworthy sources that we use

  • bestpingpong回复

    Good post. I learn something totally new and challenging on sites I stumbleupon every day.

    It's always useful to read through articles from other writers and use something from other websites.

  • Dale回复

    Have actually been taking little over a month.

  • robot gap gach回复

    I really like reading a post that can make people think.
    Also, thank you for allowing for me to comment!

  • Jose Wilame Araujo Rodrigues回复

    What's up, everything is going nicely here and ofcourse every one is sharing information, that's actually good, keep up writing.|

  • car window shade for baby回复

    Good day! This is my first visit to your blog! We are a group
    of volunteers and starting a new initiative in a community in the same
    niche. Your blog provided us useful information to work on. You have done a
    wonderful job!

  • how to use sertraline回复

    If you wish for to increase your familiarity only keep visiting
    this site and be updated with the hottest news posted here.

  • kyrie 3回复

    Spot on with this write-up, I actually think this website needs rather more consideration. I抣l probably be again to read far more, thanks for that info.

  • Blu-ray & DVD Players/Recorders回复

    fantastic publish, very informative. I wonder why the opposite specialists of this sector do not notice this. You must continue your writing. I'm confident, you've a great readers' base already!

  • DIY Style回复

    Generally I don't read post on blogs, however I wish to say that this write-up very pressured me to try and do so! Your writing taste has been surprised me. Thanks, quite great post.

  • Dry Hair回复

    It's perfect time to make some plans for the future and it is time to be happy. I have read this post and if I could I wish to suggest you few interesting things or tips. Perhaps you can write next articles referring to this article. I want to read even more things about it!

  • yeezy shoes回复

    I must show thanks to this writer just for bailing me out of such a setting. Because of browsing throughout the the net and obtaining advice which are not productive, I assumed my entire life was done. Being alive without the presence of approaches to the issues you've fixed all through the short article is a serious case, and those that could have in a negative way affected my career if I hadn't come across the blog. Your mastery and kindness in maneuvering all the pieces was useful. I don't know what I would've done if I had not encountered such a thing like this. I am able to at this moment relish my future. Thanks for your time very much for your impressive and effective guide. I will not think twice to endorse the website to anybody who needs and wants recommendations on this subject matter.

  • Auto News回复

    I really appreciate this post. I¡¦ve been looking everywhere for this! Thank goodness I found it on Bing. You have made my day! Thx again

  • LarQues回复

    No Rx Needed Thyroid [url=http://cheapvia100mg.com]viagra[/url] Venta De La Propecia Amoxicillin 500mg Diareaah Buy Propecia Germany

  • wireless system回复

    I blog frequently and I really thank you for your content.
    This article has truly peaked my interest.

    I'm going to take a note of your blog and keep checking for new information about once a
    week. I opted in for your RSS feed as well.

  • Carlos Eduardo Correa da Veig回复

    May I simply say what a comfort to uncover an individual who actually understands what they are talking about online. You definitely realize how to bring a problem to light and make it important. More people need to check this out and understand this side of your story. I was surprised that you are not more popular because you definitely possess the gift.|

  • how to use a penis pump回复

    although web sites we backlink to beneath are considerably not related to ours, we feel they're in fact really worth a go through, so have a look

  • service tax india回复

    Hey There. I found your weblog the use of msn. This
    is an extremely neatly written article. I'll be sure to bookmark it and come back to
    learn more of your helpful information. Thanks for the post.
    I will definitely return.