2011-11-02 113 views
5

我有一个工具栏在底部对齐,上面有一个WebView,用于填充剩余高度。现在,我想要滑动工具栏以隐藏它,并且在制作动画时,webview高度应该展开。我尝试过使用TranslateAnimation,但不幸的是它并没有调整工具栏的真实位置,只是它的内容被移动了。下面是我的尝试:Android向下滑动动画

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromXDelta="0%" 
    android:toXDelta="0%" 
    android:fromYDelta="0%" 
    android:toYDelta="100%" 
    android:duration="700" 
    android:fillAfter="true" /> 

和实际代码:

final View v = findViewById(R.id.browseToolbar); 
Animation animation = AnimationUtils.loadAnimation(someContext, R.anim.toolbar_hide); 
v.startAnimation(animation); 

我该怎么办呢?

回答

1

我写了一些代码来做实际的调整大小的动画。请看:

http://www.touchlab.co/blog/resize-animation/

而且看介绍我做了对Android的动画

https://docs.google.com/present/view?id=djqv5kb_187c62jvbf7

从本质上讲,如上文提到的,常规的动画类只影响什么在他们的父视图。理解它们的关键是它们不是“真实的”。将Android动画想象成海市蜃楼。如果你运行我创建的示例应用程序,假设你做了一个缩放动画,并且缩小了一个按钮,如果你点击了外部按钮,那么它仍然被注册为按钮点击。 Android动画实际上并不影响真实的边界和尺寸。

我的博客文章中的代码基本上实现了ViewGroup.OnHierarchyChangeListener。当从层次结构中添加/删除东西时,容器会动态调整物理大小。

+4

http://touchlab.co/blog/resize-animation/链接不工作 – NetStarter

0

当您使用android动画时,只会移动视图的像素。要实际移动视图,您需要向动画对象添加一个动画侦听器并覆盖onAnimationEnd方法。在该方法中,您需要以编程方式移动视图。

AnimationListener animListener = new AnimationListener() { 
    @Override 
    public void onAnimationStart(Animation arg0) {}    
    @Override 
    public void onAnimationRepeat(Animation arg0) {}     
    @Override 
    public void onAnimationEnd(Animation arg0) { 
     Move the view here   
    } 
}; 

animation.setAnimationListener(animListener);