I want to Animate two Different layouts.
Example
I already have the animation the way I want, I just want to animate a different XML Layout. There is a class LayoutAnimationController, but I really dont know how to use it. Can some one point me in the right direction, with an example or good explanation.
heres the code I use to animate.
TranslateAnimation slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 300f, 0,0 );
slide.setAnimationListener(AL);
slide.setFillAfter(true);
slide.setDuration(1000);
parentlayout.startAnimation(slide);
Update Because of the many up-votes I decided to put a example project into a Git repository. See my answers for the link.
I had the similar requirement that make layout animation like Facebook app. To do that, I made a customized ViewGroup (called AnimationLayout). Hope these code helping.
The AnimationLayout needs two child: Sidebar and Content. (by assigning @+id/animation_sidebar and @+id/animation_content to corresponding one)
This is the layout xml, the SideBar has a button and a listview. The Content has a textview and a button(it binds to a callback function).
This is the testing Activity. It initialize a ListView and assigns itself as a Listener to AnimationLayout.
This is the AnimationLayout.
When the SideBar closed, it looks like this.
When the SideBar opened, it looks like this.
I took the solution from walkingice (https://github.com/walkingice/gui-sliding-sidebar) and added to it, making a widget in which the "sidebar" can come in from the top or bottom as well as the left or right. You can also specify the sidebar width (or height) as a percent of the parent width (or height). The sidebar can be stationary behind the main content view or slide in.
The project is by SolutionStream, and it's available here: https://github.com/solutionstream/sidebarlayout
It's open source (Apache 2.0 license), so feel free to check out the code and use it (under the license), either as an example or directly.
DISCLOSURE: The above link is to a project that I created myself at SolutionStream.
Ok After spending 2 days reading about similair problems and how people solved them I finally was able to create the thing I wanted. I was not able to do it with 2 diffrent XML files, but I doubt it is not possible.
I did encountert some problems tho.
After the first animation ended, the button was not clickable. This is because the animation shows that everything is moved but it does not update the layout, so the button is still at the position where the animation started. So I had to calculate the new position of the layout.
I think I read somewhere that this is no longer an issue in 3.0, but correct me if I am wrong
Another was that when I had my animation finally working the way I wanted my underlaying view did disapear before the animation was finished because I invoked
view.setVisabilty(View.GONE);
. Now the problem was when I did not invoke that method, the animation just hang for a second and then shooter to the end position of the animation. So I added a empty LinearLayout (can be anything) , Default property on GONE, when the animation starts set it on Visible. when you revert the animation, set it again to gone. after doing this the animation was working the way I wanted.And if you are using a Rel, Linear, or any other layout. then you cant stack views in the Z order so you have to use an SurfaceView.
so heres main.xml
heres the java code
I did some extra coding on touching views and stuff.
And the final result
before Animation
after First Animation
And after the second Animation back to the left it states returns as the first Image.
Al those posts that helped me really deserve some credit but I cant find any of them.
Edit
GIT https://bitbucket.org/maikelbollemeijer/sidepanelswitcher
Update: https://github.com/jfeinstein10/SlidingMenu this lib is compatible with Actionbar Sherlock.
hope this helps