Deepika Lalra
Deepika Lalra

Reputation: 1045

translation animation issue

I want to make a layout animated through translation animation from screen's particular X Y position. and this is happening very correcty. now the problem starts when animations completes the layout again go to screen's top rihgt corner. i want the layout stay at the same position on which the animation ends.

 AnimationListener animationListener = new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation arg0) {
            drawer_layout.setVisibility(View.VISIBLE);

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            drawer_layout.setVisibility(View.VISIBLE);

        }

    };

    final Animation animTranslate = AnimationUtils.loadAnimation(this,
            R.anim.top_to_bottom_in);

    animTranslate.setAnimationListener(animationListener);

    drawer_layout = (LinearLayout) findViewById(R.id.drawer_layout);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // bitmapBackground = CaptureBackground();

            faded_layout.setBackgroundColor(Color.parseColor("#50ffffff"));

            // HandleDropAnimation(drawer_layout);
            drawer_layout.startAnimation(animTranslate);
        }
    });

and this is my xml.

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromYDelta="25%p"
android:toYDelta="50%p" />

Upvotes: 0

Views: 284

Answers (2)

Sumant
Sumant

Reputation: 2805

use before animation starts

animTranslate.setFillAfter(true);

Upvotes: 1

Lawrence Choy
Lawrence Choy

Reputation: 6108

Call

animTranslate.setFillAfter(true);

before you start the animation. According to java docs:

If fillAfter is true, the transformation that this animation performed will persist when it is finished.

Upvotes: 2

Related Questions