There's a sample application that I worked on recently with talented designer Chris Arvin for a talk we gave at DroidCon UK 2013. I also repurposed part of it for the talk about animations I gave at AnDevCon a few weeks later.
The app is open source and you can check it out here: https://github.com/dlew/android-movies-demo
You can get the APK here: https://github.com/dlew/android-movies-demo/releases/
The interactions required a bit of interesting engineering so I wanted to discuss some of it here.
ViewPager and Decor
One of the key interactions we wanted was the app to feel like a ViewPager so that it was an interaction users were familiar with except that the result isn't quite the same - instead of paging, content would slide out from underneath other content. This is not something ViewPager is inherently designed to do.
There were two options open to me. One was to rip out all of ViewPager's event handling code and make my own custom View, which was not an appealing prospect. The other was to find some way to manipulate ViewPager itself.
It turns out there is an interface ViewPager finds special called Decor. If a View implements Decor, then ViewPager treats it as a special View that can remain on top of it the ViewPager. This is normally for implementing your own tabs, but in this case I imported my own copy of ViewPager (since Decor is hidden normally) and made my entire UI a Decor View.
It's a neat trick that would work for any app that wants ViewPager event handling without paging Views, though I think if you wanted a less hacky solution you'd write your own event code.
Custom Views Everywhere
I've gone from avoiding custom Views like the plague to fully embracing them.
The key realization is that custom Views do not need to handle every situation. If you're looking at framework custom Views as reference you will be overwhelmed quickly. For example, during measurement framework Views have to handle WRAP_CONTENT, MATCH_PARENT, and everything in between; but if you know your View is always going to be MATCH_PARENT you can greatly simplify all your code.
The movies sample app is a pile of custom Views. First there's SlidingRevealViewGroup, which generically shows one View slide out from another. On top of that is built MovieRowView, which has the specific Views that we want to display. Then there's SlidingPairView, which is a set of two SlidingRevealViewGroups that creates the side-by-side effect seen in the app.
I also needed a few other custom Views to shore up some other issues. CenteringRelativeLayout just adjusts the film cover so that, as it shrinks in size, it still looks centered. SlidingListView was required for performance; we needed to manipulate the rows directly when sliding, instead of constantly notifying of data changed.
Performance Tricks
The coolest part of the whole app is the slide: how the cover becomes smaller and the content slides out from underneath. All of this was achieved through translation of Views. I took advantage of the fact that ViewGroups don't render their children outside of their own bounds. By translating content I could hide them outside the clip bounds.
When a slide starts, it throws practically everything into hardware layers then just slides Views left/right. Moving around pre-rendered content is fast and as a result the paging is silky smooth.
Nowadays I'm a huge fan of those basic properties of Views (translation, scale, rotation and alpha). They're the core reason to support ICS+ only; with these properties you can take your interactions to the next level.
Drawbacks
The drawback of the solution I came up with is that it creates a ton of overdraw. This hurts performance, especially (as far as I can tell) when rendering a new row while scrolling up/down. I sacrificed scrolling performance for paging performance. Perhaps there is a way to achieve both, but I'm pretty much done with this sample for now.
The rounded corners could've been implemented in a much better fashion than an overlaid Drawable, but with the limited time before the presentation I had, I could not come up with a better solution.
this is awesome. thanks for the Decor hint :) I think I need to pay much more attention to internal views implementation..
ReplyDeletefinal ViewPager.LayoutParams headerParams = new ViewPager.LayoutParams();
ReplyDeleteheaderParams.width = ViewPager.LayoutParams.MATCH_PARENT;
headerParams.height = ViewPager.LayoutParams.WRAP_CONTENT;
headerParams.isDecor = true;
headerParams.gravity = Gravity.TOP;
pagerView.addView(headerView, -1, headerParams);
To optimize overdraw you could just clip the bottom views with the bounds of the upper layers. This is the technique I used in this demo: http://www.youtube.com/watch?v=kOyOvT6Sp_o
ReplyDeletemaybe app that have some code like this post is popcorn time
ReplyDeleteI wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.
ReplyDeleteletmewatchthismoviedownloads.com/
Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
ReplyDeleteAWS Training in Chennai |Best Amazon Web Services Training in Chennai
AWS Training in Rajaji Nagar | Amazon Web Services Training in Rajaji Nagar
Best AWS Training Institute in BTM Layout Bangalore ,AWS Coursesin BTM
This comment has been removed by the author.
ReplyDelete
ReplyDeleteThank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
angularjs Training in online
angularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in btm
From your discussion I have understood that which will be better for me and which is easy to use. Really, I have liked your brilliant discussion. I will comThis is great helping material for every one visitor. You have done a great responsible person. i want to say thanks owner of this blog.
ReplyDeletepython training in tambaram | python training in annanagar | python training in jayanagar
This comment has been removed by the author.
ReplyDeleteWonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
ReplyDeleteJava training in Tambaram | Java training in Velachery
Java training in Omr | Oracle training in Chennai
I always enjoy reading quality articles by an individual who is obviously knowledgeable on their chosen subject. Ill be watching this post with much interest. Keep up the great work, I will be back
ReplyDeleteData Science course in kalyan nagar | Data Science course in OMR
Data Science course in chennai | Data science course in velachery
Data science course in jaya nagar | Data science training in tambaram
Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays. Well written article Thank You for Sharing with Us pmp training Chennai | pmp training centers in Chennai | pmp training institutes in Chennai | pmp training and certification in Chennai | pmp training in velachery | project management certfication in chennai
ReplyDeleteI really liked reading your article. Great work. Keep posting!
ReplyDeleteOracle Training in Chennai | Oracle Training institute in chennai | Oracle course in Chennai | Oracle Training | Oracle Certification in Chennai | Best oracle training institute in Chennai | Best oracle training in Chennai | Oracle training center in Chennai | Oracle institute in Chennai | Oracle Training near me
I am definitely enjoying your website. You definitely have some great insight and great stories.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
Interesting blog
ReplyDeleteSAP Training in Chennai
SAP ABAP Training in Chennai
SAP Basis Training in Chennai
SAP FICO Training in Chennai
SAP MM Training in Chennai
SAP PM Training in Chennai
SAP PP Training in Chennai
SAP SD Training in Chennai
Thanks for this. I really like what you've posted here and wish you the best of luck with this blog and thanks for sharing.
ReplyDeleteoracle training in bangalore
sql server dba training in bangalore
web designing training in bangalore
digital marketing training in bangalore
java training in bangalore
Thank for this blog are more informative step by step and useful contents. I here by attached my site would you see this blog.
ReplyDelete7 tips to start a career in digital marketing
“Digital marketing is the marketing of product or service using digital technologies, mainly on the Internet, but also including mobile phones, display advertising, and any other digital medium”. This is the definition that you would get when you search for the term “Digital marketing” in google. Let’s give out a simpler explanation by saying, “the form of marketing, using the internet and technologies like phones, computer etc”.
we have offered to the advanced syllabus course digital marketing for available join now
more details click the link now
https://www.webdschool.com/web-development-course-in-chennai.html
Amazing blog useful information.
ReplyDeleteWeb designing trends in 2020
When we look into the trends, everything which is ruling today’s world was once a start up and slowly begun getting into. But Now they have literally transformed our lives on a tremendous note. To name a few, Facebook, Whats App, Twitter can be a promising proof for such a transformation and have a true impact on the digital world.
we have offered to the advanced syllabus course web design and development for available join now
more details click the link now
https://www.webdschool.com/web-development-course-in-chennai.html
Nice Blog !
ReplyDeleteOur team at QuickBooks Customer Service Number will assist you in finding the right solutions for errors in this precocious situation.
포커게임When did it start? The day I started surfing the Internet to read articles related to . I've been fond of seeing various sites related to around the world for over 10 years. Among them, I saw your site writing articles related to and I am very satisfied.
ReplyDelete슬롯머신When did it start? The day I started surfing the Internet to read articles related to . I've been fond of seeing various sites related to around the world for over 10 years. Among them, I saw your site writing articles related to and I am very satisfied.
ReplyDelete릴게임When did it start? The day I started surfing the Internet to read articles related to . I've been fond of seeing various sites related to around the world for over 10 years. Among them, I saw your site writing articles related to and I am very satisfied.
ReplyDelete스포츠토토When did it start? The day I started surfing the Internet to read articles related to . I've been fond of seeing various sites related to around the world for over 10 years. Among them, I saw your site writing articles related to and I am very satisfied.
ReplyDelete