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

  • 2017-06-07
  • 0
  • 779

效果预览

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

分析

首先我们先将动画分解,这一动画分为两部分
- 翻页动画
- 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

评论

  • Health and Fitness回复

    I think this is one of the most vital information for me. And i am glad reading your article. But should remark on few general things, The website style is great, the articles is really nice : D. Good job, cheers

  • Discount Travel回复

    I have been surfing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the internet will be a lot more useful than ever before.

  • Physical Sports回复

    Hey There. I found your blog using msn. This is an extremely well written article. I’ll make sure to bookmark it and come back to read more of your useful info. Thanks for the post. I will definitely return.

  • Home Improvement回复

    Hey, you used to write fantastic, but the last several posts have been kinda boring… I miss your tremendous writings. Past several posts are just a bit out of track! come on!

  • Education回复

    Normally I don't read article on blogs, but I wish to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thank you, quite great article.

  • hooks metal clip回复

    whoah this weblog is excellent i really like studying your posts. Stay up the good paintings! You know, a lot of persons are searching around for this information, you can help them greatly.

  • Health and Fitness回复

    I have recently started a site, the information you offer on this site has helped me tremendously. Thanks for all of your time & work. "The only winner in the War of 1812 was Tchaikovsky" by Solomon Short.

  • http://www.linux.ca回复

    Therе are, of course, ѕome adverse factors
    too freelancing. Onne necessary level is thаt if you happеn to ԝork as a contract paraleցal youll not be eligible
    for the kindѕ of benefits that you would have in working for a regulation fiгm or a personsl attorney.
    In caѕe yⲟu feel thuat such “perks” as cⲟmon health
    insurance and different such advantaes are important,
    freelancing is not going to offer you these benefits.

  • painter Melbourne回复

    Thank you for some other informative site. The place else could I am getting that type of
    info written in such an ideal manner? I have a venture that I'm just now running on, and I've been at
    the look out for such information.

  • Health and Fitness回复

    I'll right away grab your rss feed as I can't in finding your email subscription hyperlink or newsletter service. Do you have any? Kindly let me recognize in order that I may subscribe. Thanks.

  • how the madden mobile hack works回复

    The process is very simple to make use of the Madden Mobile hack instrument.
    What you need to create are submit your own login name.
    Immediately ensure you know your username
    (which can be found during the settings). Lots of people attempt to utilize the e-mail they opted with, it is
    not correct. After getting into your own user name, select the equipment that you're currently using and choose whether or otherwise not you prefer to need a proxy utilizing the hack device.
    Next you may wish to select level of coins, funds, stamina or XP you would like.
    Recall you can select an unlimited quantity.
    Then the hack will endeavor and you'll magically see
    all of the brand new cash, strength, coins and
    XP added to your account.

    Utilizing the Madden Mobile hack correctly

    Heed these basic steps below.

    Enter the Madden Mobile Login Name.
    Choose the unit you're currently using.
    Identify whether or perhaps not to utilize a proxy.

    Pick any level of Coins, earnings, Stamina, or XP to
    increase your bank account.
    Enable the hack to procedure.
    Relaunch Madden Mobile.

    Welcome to our very own web site. Do you have hassle to find Madden NATIONAL FOOTBALL LEAGUE Mobile hack
    to obtain unlimited money and funds? And you’re tired and fatigued to consider it.
    Dont worry you could get it-all here with no charges or
    no-cost.
    To understand more about how madden mobile hack tool works and madden mobile tips and tricks, please go to all of our website how the madden mobile hack works.

    How To Achieve Greater Offense?

    Best crime suggests increased odds of growing champ at the conclusion of the game.
    In order to achieve the cause, as a new player, you need to render
    initiatives to perfect current Madden Mobile 17 qualities and enhancements.

    Participants must comprehend the offense strategies used in Madden 16 will likely not work with Madden17.
    Only make use of these tips and overcome the strong foes.

    Learn how to Apply The Option – Anytime as a person, you are
    not able to deal with the pressure during the video game,
    better is to discard the basketball using the correct
    stick. With this specific, you may make sure the
    success with intentional grounding was avoided.
    This is an extremely essential feature as compared to Madden 16 as the
    application of brand new ball physics enables the quarterback with less probability
    to carry onto the ball. Merely don’t fumble and employ this feature to your
    advantage.
    Application Of Madden 17 Hack Cheats Plays – In recent years many
    new amazing artificial has have been launched for Madden Mobile 17.
    continue to keep your self current with current happenings into the online game.
    Target device icon in order to make optimal utilization of opportunity.

    Gain Knowledge About Player’s scores – Looking at player’s
    ranks and discovering the moves in which these are generally good is a perfect tip.
    With this specific latest feature, it will being feasible to
    work through the best action associated with player and place him correctly.
    Essentially, you must have your personal teams set-up when you look at the game and prepare a method according to the readily available participants.

    Discover Running techniques – There are many working techniques within the Madden Mobile
    17 that you must read out correctly. With these techniques, it will become feasible to obtain additional yards on offense and improve
    your chances of profiting the video game.

  • Health and Fitness回复

    I am also commenting to let you know what a magnificent discovery our girl found using yuor web blog. She figured out a wide variety of pieces, not to mention how it is like to have an amazing coaching heart to have others easily fully grasp some extremely tough topics. You actually did more than our own expected results. I appreciate you for offering the valuable, trustworthy, edifying and even cool tips on the topic to Evelyn.

  • Health and Fitness回复

    A person necessarily lend a hand to make significantly articles I'd state. This is the very first time I frequented your web page and thus far? I amazed with the analysis you made to create this particular post incredible. Great activity!

  • Health and Fitness回复

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

  • Health and Fitness回复

    Somebody necessarily lend a hand to make critically articles I might state. That is the very first time I frequented your web page and so far? I amazed with the research you made to create this particular submit amazing. Excellent task!

  • Enterprise回复

    Hi there, You've done a great job. I’ll definitely digg it and personally recommend to my friends. I'm confident they will be benefited from this website.

  • Dry ice packs回复

    This website online is really a walk-by for all the information you wanted about this and didn’t know who to ask. Glimpse here, and also you’ll undoubtedly discover it.

  • Health and Fitness回复

    Needed to write you one little bit of remark to be able to give thanks the moment again for all the lovely ideas you have shown on this page. It is so strangely open-handed of people like you giving easily what some people could possibly have distributed for an electronic book to end up making some dough for themselves, chiefly seeing that you could have done it in case you wanted. These techniques as well acted to be a great way to understand that some people have the identical keenness the same as my own to grasp more concerning this condition. I know there are millions of more fun occasions in the future for many who scan your blog post.

  • Dannie回复

    It's actually very difficult in this full of activity
    life to listen news on Television, therefore I simply use world
    wide web for that reason, and get the most up-to-date
    news.

  • pro回复

    Hi my family member! I want to say that this post is amazing, great written and come with approximately all significant infos. I¡¦d like to see extra posts like this .

  • Health and Fitness回复

    It¡¦s really a nice and helpful piece of info. I¡¦m happy that you shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.

  • Health and Fitness回复

    I was reading through some of your content on this website and I think this internet site is very instructive! Continue putting up.

  • Health and Fitness回复

    Very nice post. I just stumbled upon your blog and wished to say that I've truly enjoyed surfing around your blog posts. After all I will be subscribing to your feed and I hope you write again very soon!

  • 동화세상에듀코回复

    please pay a visit to the websites we comply with, including this one particular, as it represents our picks in the web

  • Health and Fitness回复

    you're truly a just right webmaster. The web site loading velocity is amazing. It kind of feels that you're doing any unique trick. Moreover, The contents are masterpiece. you've done a wonderful activity in this matter!

  • Health and Fitness回复

    I have not checked in here for a while as I thought it was getting boring, but the last few posts are good quality so I guess I will add you back to my daily bloglist. You deserve it my friend 😊

  • tibiabr回复

    usually posts some extremely fascinating stuff like this. If you are new to this site

  • Health and Fitness回复

    Hi my loved one! I wish to say that this article is amazing, great written and come with approximately all vital infos. I¡¦d like to look more posts like this .

  • usuwanie dpf回复

    Here are a few of the web sites we advise for our visitors

  • Health and Fitness回复

    Valuable info. Fortunate me I discovered your website by chance, and I am stunned why this coincidence didn't happened earlier! I bookmarked it.

  • click here for more回复

    I’m not that much of a online reader to be honest but your blogs really nice, keep it up!
    I'll go ahead and bookmark your site to come back later.
    Many thanks

  • Health and Fitness回复

    I precisely wanted to say thanks again. I do not know what I could possibly have gone through without those methods shared by you over my subject matter. It truly was a scary circumstance for me, nevertheless viewing this well-written technique you handled it made me to cry for contentment. Extremely happier for your advice and sincerely hope you find out what a great job that you're carrying out educating the others through a blog. I know that you've never come across any of us.

  • Health and Fitness回复

    Just want to say your article is as astounding. The clarity in your post is simply spectacular and i can assume you're an expert on this subject. Well with your permission allow me to grab your feed to keep up to date with forthcoming post. Thanks a million and please carry on the enjoyable work.

  • kit de uñas de gel回复

    This is the fitting weblog for anybody who wants to seek out out about this topic. You notice so much its virtually exhausting to argue with you (not that I truly would want…HaHa). You definitely put a new spin on a topic thats been written about for years. Nice stuff, simply nice!

  • Health and Fitness回复

    I precisely wished to appreciate you yet again. I'm not certain what I could possibly have gone through in the absence of those suggestions documented by you concerning my industry. Certainly was an absolute frightening setting in my view, but being able to see a expert avenue you treated it took me to weep over fulfillment. Now i'm thankful for the work and believe you find out what an amazing job you are always carrying out educating the rest thru your webblog. I am sure you haven't encountered all of us.

  • Education回复

    Fantastic site. Lots of useful info here. I'm sending it to several buddies ans also sharing in delicious. And of course, thanks on your effort!

  • Health and Fitness回复

    Pretty section of content. I just stumbled upon your site and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently quickly.

  • kit de uñas de gel回复

    It is truly a great and helpful piece of info. I am happy that you shared this useful information with us. Please stay us up to date like this. Thank you for sharing.

  • Health and Fitness回复

    I think this is among the most vital information for me. And i'm glad reading your article. But should remark on few general things, The site style is ideal, the articles is really great : D. Good job, cheers

  • Health and Fitness回复

    Great blog here! Also your website loads up fast! What host are you using? Can I get your affiliate link to your host? I wish my website loaded up as fast as yours lol

  • wedding dresses Mississauga回复

    excellent issues altogether, you simply won a logo new reader. What would you recommend in regards to your submit that you just made some days in the past? Any positive?

  • midrag回复

    I would like to thnkx for the efforts you've put in writing this site. I am hoping the same high-grade website post from you in the upcoming as well. In fact your creative writing skills has encouraged me to get my own site now. Really the blogging is spreading its wings quickly. Your write up is a good example of it.

  • Health and Fitness回复

    Only a smiling visitant here to share the love (:, btw outstanding design and style .

  • Education回复

    As soon as I found this website I went on reddit to share some of the love with them.

  • Fashion Island回复

    Thank you for every other magnificent post. The place else may anyone get that type of info in such a perfect means of writing? I've a presentation next week, and I am on the look for such information.

  • Health and Fitness回复

    I¡¦ve learn several just right stuff here. Certainly price bookmarking for revisiting. I surprise how a lot attempt you put to create this type of great informative site.

  • Cooler Math回复

    Thank you for sharing superb informations. Your web-site is very cool. I am impressed by the details that you¡¦ve on this site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my friend, ROCK! I found just the information I already searched all over the place and simply couldn't come across. What a perfect site.