androidevil
androidevil

Reputation: 9171

How can I make my animation goes from the bottom to top of my screen?

This is my xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <SurfaceView
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="0dp" />

</RelativeLayout>

I want to make this view grow with the time.

Here is the code for animation

SurfaceView surfaceViewTimer = (SurfaceView) findViewById(R.id.surface_view_timer);
Animation surfaceGrowingAnimation = new TranslateAnimation
    (0, 0, Animation.ZORDER_TOP, 300);
surfaceGrowingAnimation.setDuration(5000);

surfaceViewTimer.startAnimation(surfaceGrowingAnimation);

I want to make this animation goes from the bottom to top of the screen. Currenty it is going from the top to the bottom.

Upvotes: 2

Views: 4134

Answers (3)

Priety
Priety

Reputation: 308

You can do it by combining Scaling and Translate Animation.Translate Animation will help in the change in position of the view while the Scale in animation will help in the Change of Size. And in your code use Accelerate_Decelerate interpolator. The interpolator will give the required effect. You can try out with the different types of available interpolators to achieve the effect.

Upvotes: 1

sdabet
sdabet

Reputation: 18670

You can use a ScaleAnimation.

For instance, modify the layout so that the surface takes whole screen:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<SurfaceView
    android:id="@+id/surface"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="0dp"
    android:background="@color/red"
     />

And then scale it on Y-axis from 0 to 1:

    SurfaceView surface = (SurfaceView) findViewById(R.id.surface);

    ScaleAnimation animation = new ScaleAnimation(1.0f, 1.0f, 0.0f, 1.0f);
    animation.setDuration(5000);
    surface.startAnimation(animation);

Upvotes: 2

sdabet
sdabet

Reputation: 18670

You can do it with a TranslateAnimation like this:

    final SurfaceView surface = (SurfaceView) findViewById(R.id.surface);

    surface.post(new Runnable() {
        @Override
        public void run() {
            TranslateAnimation translation = new TranslateAnimation(0f, 0f, surface.getHeight(), 0f);
            translation.setDuration(2000);
            surface.startAnimation(translation);
        }
    });

Upvotes: 1

Related Questions