Show and hide a View with a slide up/down animation

With the new animation API that was introduced in Android 3.0 (Honeycomb) it is very simple to create such animations. Sliding a View down by a distance: view.animate().translationY(distance); You can later slide the View back to its original position like this: view.animate().translationY(0); You can also easily combine multiple animations. The following animation will slide a … Read more

How do I fade an image in swing?

You can do the threading yourself, but it might be easier to use the Trident library to handle it. If you create a setter on your class called (say, setOpacity), you can ask trident to interpolate the “opacity” field from 1.0 to 0.0 over a specific period of time (here’s some of the docs on … Read more

Animate change of view background color on Android

You can use new Property Animation Api for color animation: int colorFrom = getResources().getColor(R.color.red); int colorTo = getResources().getColor(R.color.blue); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { textView.setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); For backward compatibility with Android 2.x use Nine Old Androids library from Jake … Read more

How to change the Push and Pop animations in a navigation based app

I did the following and it works fine.. and is simple and easy to understand.. CATransition* transition = [CATransition animation]; transition.duration = 0.5; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade //transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom [self.navigationController.view.layer addAnimation:transition forKey:nil]; [[self navigationController] popViewControllerAnimated:NO]; And the same thing for push.. Swift … Read more

How to make an image move while listening to a keypress in Java.

Yep, a Swing Timer and Key Bindings would work well. Here’s another example (mine) 🙂 import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import javax.swing.*; public class AnimationWithKeyBinding { private static void createAndShowUI() { AnimationPanel panel = new AnimationPanel(); // the drawing JPanel JFrame frame = new JFrame(“Animation With Key Binding”); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } … Read more

How to Use slideDown (or show) function on a table row?

Animations are not supported on table rows. From “Learning jQuery” by Chaffer and Swedberg Table rows present particular obstacles to animation, since browsers use different values (table-row and block) for their visible display property. The .hide() and .show() methods, without animation, are always safe to use with table rows. As of jQuery version 1.1.3, .fadeIn() … Read more

Android Left to Right slide animation

Use this xml in res/anim/ This is for left to right animation: <set xmlns:android=”http://schemas.android.com/apk/res/android” android:shareInterpolator=”false”> <translate android:fromXDelta=”-100%” android:toXDelta=”0%” android:fromYDelta=”0%” android:toYDelta=”0%” android:duration=”700″/> </set> This is for right to left animation: <set xmlns:android=”http://schemas.android.com/apk/res/android” android:shareInterpolator=”false”> <translate android:fromXDelta=”0%” android:toXDelta=”100%” android:fromYDelta=”0%” android:toYDelta=”0%” android:duration=”700″ /> </set> In your coding use intent like for left to right: this.overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave); In your coding … Read more

Android: Expand/collapse animation

I see that this question became popular so I post my actual solution. The main advantage is that you don’t have to know the expanded height to apply the animation and once the view is expanded, it adapts height if content changes. It works great for me. public static void expand(final View v) { int … Read more