为什么OnAnimationEnd移动按钮的初始位置,但也移动按钮本身? @。@

时间:2015-08-15 17:23:36

标签: android animation android-studio

我对我创建的按钮做了一些动画。但是,在动画之后,按钮处于新位置,但是onclick功能处于其旧的初始位置。我做了onAnimationEnd并将按钮设置到新位置,但Button和带有onclick功能的隐形按钮一起移动。任何帮助都会很棒

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {


//move
        TranslateAnimation animation = new TranslateAnimation(0.0f, ((widthPixels / 2) - 100),
                0.0f, 0.0f);
        animation.setDuration(1000);
        animation.setRepeatCount(0);
        animation.setRepeatMode(0);
        animation.setFillEnabled(true);
        animation.setFillAfter(true);

        //fade
      //  Play.setVisibility(View.VISIBLE);
        Play.startAnimation(animationfadein);
        Play.startAnimation(animation);
        Play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(DreamTales.this, Stories.class);
                startActivity(i);
            }

        });


    }
}, DELAY);

  animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {

  Button Playghost = (Button) findViewById(R.id.PlayBtn);
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)Play.getLayoutParams();
            lp.leftMargin = (widthPixels/100); // use topmargin for the y-property, left margin for the x-property of your view
            Playghost.setLayoutParams(lp);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

0 个答案:

没有答案