Android Parallax - offsetPixel - android

I am trying to design a complicated parallaxing animation that resides inside a ViewPager. The animation uses onPageScrolled function's offsetPixel to calculate the position of the images.
However this approach is causing a lot of problems due to the offsetPixel if scrolled fast can skip (ex: 1 to 123 to 250 to 251) and when slow it's too sensitive so the animation seems jittery.
Is there a better way to calculate the position of the screen besides offsetPixels. If so, can anyone please help me figure it out. Would appreciate it very much!
Thank you.

Well, I don't know exactly if one of the pages has to have the parallax effect, or it has to been a parallax effect between de transition of changing pages.
I developed a small library to make the second one, https://github.com/xgc1986/ParallaxPagerLibrary
Demo: parallax demo
This library work with Views, the you can use it with imageViews to have the effect.
To do that I don't use de onPageScrolled function, basically then you don't permit to the developer to use this listener anymore, the to solve that I implemented a child of PageTransformer

Related

How to implement animations/transitions in Android

I have a specific goal regarding animation using Recyclerview, but I cant find an exact title to convey my concern, so I'm open to any correction if necessary. So first , I have a recyclerview that acts as a ViewPager thanks to David Medenjak's Recyclerview ViewPager
Now I have a requirement to animate the background color for each swipe transition, thanks to different links and resources, I stumbled upon TransitionDrawables, putting an array of different drawables and invoking a necessary transition functions to animate,
recyclerView.setBackground(arrayOfDrawables)
transitionArrayOfDrawables.startTransition(...);
Now I want to take things deeper, I want to manually control the transition relative to the animation of the swipe of each item of the recyclerview, Im mentally blocked as I cant find the keyword to search for where should I start, "Interpolation", "Manually interpolating a views animation", things like that, but still no luck, the only thing that I have on my mind is "Get the recyclerview's visible item's interpolation/animation-value then supply it to the target view's animation manually", but I dont know where to start, I dont even know how to animate view's manually, I have experience with ObjectAnimators, simple translating, scaling, bouncing etc.. but controlling view's animation manually and relatively even by using knob/seek bar or such, its just out of my domain as of the moment.
Any help would be greatly appreciated.
[Edit] Apologies if my question's intent covers alot of demands :(
If I am understanding correctly, this link may be of some use. It provides instruction for how to gradually transition between viewpager background colors in relation to the user swipe.
The example uses the ArgbEvaluator class which -according to the doc: "...perform[s] type interpolation between integer values that represent ARGB colors."

"The type Gallery is deprecated", Whats the best alternative?

I was really surprised that such a Widget gets deprecated.
I want a simple gallery that scrolls left and right, shows a picture on the whole Activity screen, and most important is that you cant swipe more than 1 image in any direction, even if the scroll speed is fast it changes to the next image.
So which Widget should I use? Or should I use a simple ImageView and handle all the swipes and add an animation?
It states in the docs:
This widget is no longer supported. Other horizontally scrolling widgets include HorizontalScrollView and ViewPager from the support library.
HorizontalScrollView will be closer to what you are looking for I think.
I suspect that Gallery was deprecated because it did not properly use convertView with its adapter. Which meant that it had to create a new view for every item which was a drain on performance.
Another option you have is to use the 3rd party created EcoGallery which Joseph Earl created to overcome the issue, this version does recycle its views properly. Unfortunately that pastebin link is the only reference to it I can find online now.

Animated sequence of views

I want to implement view like this:
Inside of this view all children has to be animated while scrolling through them.
I am going to implement it for android 2.x
My first thought was to create custom view extending FrameLayout and manage children views inside programatically, detect gestures and move to next/prev child view animating them (probably scale and transition animation)
What can you advice me, how to achive that, maybe there is an open source project that can help me?
Finally I got what I wan't, there is no simple answer on this question, but simply saying you have to all the work that android UI framework usually does: calculate position of items, add them in proper order, apply different effects (translate, scale, fade out) and draw it on canvas.
To achiev this I follod this extremely useful tutorial (thanks to author)
http://blogs.sonyericsson.com/wp/2010/05/20/android-tutorial-making-your-own-3d-list-part-1/
I am thinking to add my solution somewhere on github once I fix all bugs and make it completelly reusable.

Animate GridView Children

I was wondering if there is a way that I can animate my GridView's Children to their new positions. So, for example, slide in from the left and when at the end of a row, slide off to the right. This will give the effect of each child moving to its new position, rather than just appearing there.
I have looked around, and could not find any useful information. Ideally a small code sample will get me on my way.
Thanks
You should consider using GridLayoutAnimationController. GridLayoutAnimationController docs
You may try looking at this video:
http://www.youtube.com/watch?v=X984r7IOrgc
The developer somehow shares how he had implemented the animation in his reply on one of the comments. He could not show the source code yet though. Hope this helps.
i used android canvas and some code for positioning image tiles. it
uses and data adapter pattern (like for all AdapterViews). each tile
has it's position - page, row and column. draging changes tiles
positions. - karooolek
There are a few animations in the Android API Demo, including some animations for gridview.
You might want to check the examples in com.example.android.apis.view.

What is the best approach to implement horizontal scrolling carousel component?

I'm trying to figure out the best approach to design a horizontal scrollview with only a few buttons that when scroll if end is reached it starts showing the first items again hence carousel behavior.
By carousel behavior I'm not saying 3D circle carousel, I just mean that you can continue scrolling horizontally, forever, and the first item shows up again when the end is reached, for example when scrolling swiping to the left.
Any suggestions would be greatly appreciated.
This is way in the future to be useful to the original poster, but for any others who stumble upon this question, I created a custom view that does exactly what Benjamin wanted:
https://github.com/moldedbits/infinitely-scrolling-carousel
You might try this, http://code.google.com/p/infinite-gallery/
If that doesn't work then I don't understand the question and you might want to try and give a bit more detail as to why it doesn't meet your needs
If by carousel ( a rather subjective term) you mean each item has a different "depth" with the center item the most prominent in so far as the UI there are other projects that have done this too

Categories

Resources