需要帮助的意见动画的android [英] need help for animation of views in android

查看:182
本文介绍了需要帮助的意见动画的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过大量TUTS和示例我的要求奔赴但我仍然认为我的地方失去了一些东西。

I went through lots of tuts and examples for my requirement but still I think I am missing something somewhere.

我试图隐藏和显示用幻灯片视图和向下滑动动画。

I am trying to hide and show a view with slide up and slide down animation.

这里是我期待的。

图1(点击按钮1日前)

fig 1(before button 1 is clicked)

============================
|       view1              |
============================
| button 1 |
============

图2(1按钮点击后)

fig 2 (after button 1 is clicked)

============================
|       view1              |
============================
|                          | 
|       view 2             |
|                          |
============================
| button 1 |
============

你可以看到我想要显示和隐藏视图2当我点击按钮1

as you can see I want to show and hide view2 when I click on button 1

我设法通过以下code做到这一点。

I have managed to do this by the following code

要隐藏

TranslateAnimation slide = new TranslateAnimation(0, 0,0,-200);
slide.setDuration(1000);
slide.setFillAfter(true);
view2.startAnimation(slide);
view2.setVisibility(View.GONE);

要查看

TranslateAnimation slide = new TranslateAnimation(0, 0,-200,0);
slide.setDuration(1000);
slide.setFillAfter(true);
view2.startAnimation(slide);
view2.setVisibility(View.VISIBLE);

这工作正常,但在code两个唯一的问题是完成动画之前的'飘'和'可见'code完毕。即按钮1点击显示和动画以后建成后向下移动。同样的情况对于隐藏的按钮1,如果完成了动画之前向上移动

This works fine but the only problem in both the code is that the 'Gone' and 'Visible' code is completed before the animation is completed. i.e. 'button 1' moves down when clicked to show and the animation is completed later. same happens for hide, the 'button 1' moves up before the animation if completed

我要与动画一起动按钮

请帮忙...

拉​​吉

我如何

推荐答案

该动画的方法setAnimationListener(AnimationListener)。 AnimationListener有树回调

the animation has the method setAnimationListener(AnimationListener). AnimationListener has tree callback


  1. onAnimationStart

  2. onAnimationRepeat

  3. onAnimationEnd

您可以更改可见性时onAnimationEnd被调用。

you can change the visibility when the onAnimationEnd is called.

例如:

slide.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
                              // here you can change the visibility
        }
);

这篇关于需要帮助的意见动画的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆