Android Flip vertical animation xml - android

i want to create Flip vertical animation in my application but all of my found document are flip horizontal and i can not find any document about flip vertical by xml or java class

You can achieve this by putting two views of the same size one below the other and use the ViewPropertyAnimator like this:
firstView.animate().rotationX(90).setDuration(200).setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
firstView.setVisibility(View.GONE);
secondView.setRotationX(-90);
secondView.setVisibility(View.VISIBLE);
secondView.animate().rotationX(0).setDuration(200).setListener(null);
}
});
The first view is visible when starts, and the second one, obviously it's invisible.

Related

How to refresh a layout after ObjectAnimator

I try to do a menu with a hide button. When I press the hide button, i do objectAnimator= ObjectAnimator.ofFloat(myLayout, "translationY"... to move the layout up.
My problem is when I move all the layout up, it didn't grow, it only move up with his fixed size. I don't know how to refresh the size of the layout to match_parent so my 2nd layout will take all the place.
Thanks
Kick off example:
ObjectAnimator anim = ObjectAnimator.ofFloat(myLayout, "translationY"...);
anim.addListener(new AnimatorListener() {
#Override
public void onAnimationEnd(Animator animation) {
((RelativeLayout.LayoutParams) view.getLayoutParams).width = ViewGroup.LayoutParams.MATCH_PARENT;
}
});
I think you can't achive this effect using only translation. Translating object still keep its bounds in layout (you can see it when you turn on Developer options -> Show layout bounds on your device). It's just drawing in a different place.
I don't know what you exactly want to do, so if that tip is not enough, try to give more details. For now I can only propose animating one of your views' height.

Animate removing views from complex scrollview

I am trying to remove some Views from a ScrollView, but do so with a nice animation effect.
Unfortunately, android:animateLayoutChanges does not appear to work inside ScrollView with multiple ViewGroups. More precisely, in that case you can only apply it to a subset view. In such a situation, however, the other views will still adjust by jumping into position.
I have used TranslateAnimation to slide everything inside a ScrollView into place, removing the views onAnimationEnd. This appears only to work if a ScrollView does not scroll (content smaller than ScrollView size).
Simplified code:
Animation animation = new TranslateAnimation(0, 0, 0, -ViewToBeRemoved.getHeight());
animation.setAnimationListener(new AnimationListener() {
...
#Override
public void onAnimationEnd(Animation animation) {
viewToBeRemoved.setVisibility(View.GONE);
}
}
scrollViewChildView.startAnimation(animation);
Is there a way to remove Views from a ScrollView with an animation?

Correct way of hiding a view using an animation?

I've tried several ways of hiding a view and then removing it from the parent layout:
Call an alpha fade animation followed by a call to setVisibility(GONE);
Call an alpha fade animation followed by a call to setVisibility(GONE) inside of the AnimationListener
Call an alpha fade animation followed by removing the parent layout inside of the AnimationListener.
Each time, the resulting animation fails --- the view disappears twice from the screen. The alpha fade animation works fine but when you change the visibility or remove it from the parent view, it quickly reappears again before disappearing a second time. The result is an unexpected jittery animation.
Example code:
Animation animation = AnimationUtils.loadAnimation(AddTaskActivity.this,
R.anim.fade_out);
final LinearLayout parentView = (LinearLayout) findViewById(R.id.addtask_root);
animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationEnd(Animation animation) {
parentView.post(new Runnable() {
public void run() {
parentView.removeView(test);
}
});
}
That animation fails---the test view disappears twice from view.
Any ideas?
I guess that if you transparent your view before remove it or change it's visibility,you can do what you want:
#Override
public void onAnimationEnd(Animation animation) {
parentView.post(new Runnable() {
public void run() {
// transparent your view
...
parentView.removeView(test);
}
});
Edit:
I saw android documentation in about animations and it says:
Another disadvantage of the view animation system is that it only
modified where the View was drawn, and not the actual View itself. For
instance, if you animated a button to move across the screen, the
button draws correctly, but the actual location where you can click
the button does not change, so you have to implement your own logic to
handle this.
With the property animation system, these constraints are completely
removed, and you can animate any property of any object (Views and
non-Views) and the object itself is actually modified. The property
animation system is also more robust in the way it carries out
animation. At a high level, you assign animators to the properties
that you want to animate, such as color, position, or size and can
define aspects of the animation such as interpolation and
synchronization of multiple animators.
So I guess that you have to use property animation.

Android slide down animation

I have a toolbar aligned at the bottom and a WebView above it, which fill remaining height. Now I want to slide down the toolbar in order to hide it, and while it's animating the webview height should expand. I've tried using TranslateAnimation but unfortunetely it's not adjusting toolbar's real position, only it's contents are moved. Here's what I tried:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="100%"
android:duration="700"
android:fillAfter="true" />
And the actual code:
final View v = findViewById(R.id.browseToolbar);
Animation animation = AnimationUtils.loadAnimation(someContext, R.anim.toolbar_hide);
v.startAnimation(animation);
How can I do it?
I wrote some code to do actual resize animations. Take a look:
http://www.touchlab.co/blog/resize-animation/
Also look at a presentation I did on Android animation
https://docs.google.com/present/view?id=djqv5kb_187c62jvbf7
Essentially, as mentioned above, the regular animation classes only affect what's in their parent view. The key to understanding them is they aren't "real". Think of the Android animation as a mirage. If you run the example app I created, say you do a scale animation and make a button smaller, if you click outside, where the button USED to be, it still registers as a button click. Android animations don't actually affect real boundaries and dimensions.
What the code in my blog post does, essentially, is implement a ViewGroup.OnHierarchyChangeListener. When stuff is added/removed from the hierarchy, the container animates a physical resize.
When you use android animation only the pixels of the view are shifted. To actually move the view, you will need to add an animation listener to the animation object and override the onAnimationEnd method. In that method you need to programatically move the view.
AnimationListener animListener = new AnimationListener() {
#Override
public void onAnimationStart(Animation arg0) {}
#Override
public void onAnimationRepeat(Animation arg0) {}
#Override
public void onAnimationEnd(Animation arg0) {
Move the view here
}
};
animation.setAnimationListener(animListener);

How can I make an ImageView NOT show until after my animation has run?

I have an activity that is a blank screen except for one ImageView object that has it's gravity set to center. Then in my res\anim directory, I animate that image, basically moving it from the bottom of the screen to the center (rising up), using . What I'm trying to figure out is how to have the activity load with a blank screen, not showing the ImageView until after the animation finishes with the image centered. What happens right now is the screen shows with the image already in the center, then the animation takes over and moves it from bottom to top. How Can I make the animation happen first, before showing the ImageView?
EDIT...Please see new/related question below:
OK, the .setVisibilty works (thanks for the help), but it's led me to another problem. In my xml layout file for this activity, I only have 2 objects, a TextView at the top of the screen (using LinearLayout) and then an ImageView that is set to:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView android:id="#+id/Image01"
android:src="#drawable/image_01"
android:layout_height="150dp"
android:layout_width="200dp"
android:paddingTop="10px"
>
</ImageView>
</LinearLayout>
This puts the image dead center of the screen. What I want the animation to do is have the image rise from the bottom of the screen to the center. The problem is that even if I have the .setVisibility to INVISIBLE in the onCreate, then set to VISIBLE after I start the animation, it still flashes the image in the dead center of the screen (for about half a second), then immediately drops to the bottom and rises back up to center. This looks sloppy. How can I make the image never show until appears at bottom then rise to the center? I beg for specifics, as I'm just getting feet wet with java and xml.
Final EDIT...
Never mind, this only seems to happen in the emulator. It works fine on the phone.
Thanks for all your help everyone.
Make sure that your image is invisible when the activity starts, by setting the android:visibility attribute to invisible, or by using setVisibility() in onCreate().
Then start the animation and call setVisibility(View.VISIBLE) in one go:
image.startAnimation(...);
image.setVisibility(View.VISIBLE);
I think you want to look at theImageView.setVisibility(View.INVISIBLE).
And you can get information on what your animation is doing (if it's done) with an AnimationListener.
The AnimationListener will have something like this:
AnimationListener a_to_b = new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// Do something
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
// Do something
}
};
and you set it by:
Animation ani = AnimationUtils.loadAnimation(this, R.anim.ani);
ani.setAnimationListener(a_to_b);
Hope this helps

Categories

Resources