如何为动画后的视图编写 onclick 监听器?

发布于 2024-12-23 16:53:35 字数 209 浏览 4 评论 0原文

我已将视图从一个地方动画到另一个地方,动画完成后我编写了这样的代码,

    public void onAnimationEnd(Animation animation) {
            imageView.setOnClickListener(this); 
        }

但我无法单击该视图。该观点没有得到回应。

I have animating the view from one place to another, after animation done I have written the code like this,

    public void onAnimationEnd(Animation animation) {
            imageView.setOnClickListener(this); 
        }

But I cant able to click that view. No response from that view.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∝单色的世界 2024-12-30 16:53:35

您应该将动画后的视图移动到新位置。您可以使用布局参数。

You should move the view after the animation to the new position. You can use LayoutParams.

阿楠 2024-12-30 16:53:35

您应该将动画后的视图移动到新位置。您可以使用布局参数。使用这样的代码..

      transAnimation= new TranslateAnimation(0, 
 sourceX-destinationX,0,sourceY-destinationY); // right to left

             transAnimation.setDuration(1000);
             //transAnimation.setFillEnabled(true);
             transAnimation.setFillAfter(false);
             view.startAnimation(transAnimation);

transAnimation.setAnimationListener(new AnimationListener() {

                    @Override
public void onAnimationStart(Animation animation) {
                    }

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

@Override
public void onAnimationEnd(Animation animation) {

Log.v("hari", "--------onAnimationEnd--------");

RelativeLayout.LayoutParams relativeNew 
  = new    RelativeLayout.LayoutParams(
 LayoutParams.WRAP_CONTENT,
  LayoutParams.WRAP_CONTENT);
          relativeNew.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
         relativeNew.addRule(RelativeLayout.ALIGN_LEFT);
     relativeNew.setMargins(125, 10, 10, 10);
    view.setLayoutParams(relativeNew);

 }

You should move the view after the animation to the new position. You can use LayoutParams. use the code like this..

      transAnimation= new TranslateAnimation(0, 
 sourceX-destinationX,0,sourceY-destinationY); // right to left

             transAnimation.setDuration(1000);
             //transAnimation.setFillEnabled(true);
             transAnimation.setFillAfter(false);
             view.startAnimation(transAnimation);

transAnimation.setAnimationListener(new AnimationListener() {

                    @Override
public void onAnimationStart(Animation animation) {
                    }

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

@Override
public void onAnimationEnd(Animation animation) {

Log.v("hari", "--------onAnimationEnd--------");

RelativeLayout.LayoutParams relativeNew 
  = new    RelativeLayout.LayoutParams(
 LayoutParams.WRAP_CONTENT,
  LayoutParams.WRAP_CONTENT);
          relativeNew.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
         relativeNew.addRule(RelativeLayout.ALIGN_LEFT);
     relativeNew.setMargins(125, 10, 10, 10);
    view.setLayoutParams(relativeNew);

 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文