0

i simply can't find the solution for my problem. I hope anybody can help. For android I'm trying to slide down a view and after 3 seconds it has to slide up automatically.

The first time I start the method it's well! The view slides down and after a while it slides up again automatically.

The second time I start the method nothing happens. No view is shown! Not even the view slides down. (textView is a TextInputEditText)

    public void slideDown() {
        textView.animate().translationY(100).setStartDelay(350);
        textView.animate().translationY(0).setStartDelay(3000);
    }

    public void initAnimation() {
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        textView.setLayoutParams(layoutParams);
        textView.setGravity(Gravity.CENTER);
        textView.setPadding(1000, 10, 1000, 10);
        textView.animate().translationY(100);
    }

I tried to orientate on this forum entry Slide Down & Slide Up

Peter
  • 87
  • 1
  • 6

2 Answers2

0

Hello @Peter try this it will help you

    import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;

public class AnimationActivity extends AppCompatActivity {


    TextView tvTitle;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation);
        tvTitle = findViewById(R.id.tvTitle);
        slideUp();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                slideDown();
            }
        }, 3000);
    }

    public void slideDown() {
        TranslateAnimation animate = new TranslateAnimation(
                0,                 // fromXDelta
                0,                 // toXDelta
                0,                 // fromYDelta
                500); // toYDelta
        animate.setDuration(500);
        animate.setFillAfter(true);
        tvTitle.startAnimation(animate);
    }

    public void slideUp() {
        TranslateAnimation animate = new TranslateAnimation(
                0,                 // fromXDelta
                0,                 // toXDelta
                500,  // fromYDelta
                0);                // toYDelta
        animate.setDuration(1000);
        animate.setFillAfter(true);
        tvTitle.startAnimation(animate);
    }
}
Nilesh Panchal
  • 1,059
  • 1
  • 10
  • 24
0

Thx I did it this way:

public void slideDown() {
    textView.animate().translationY(100).setDuration(500);

    textView.postDelayed(new Runnable() {
        @Override
        public void run() {
            //Do something after 3000ms
            textView.animate().translationY(0).setDuration(300);
        }
    },3000);
}
Peter
  • 87
  • 1
  • 6