Android 下滑动画
我有一个底部对齐的工具栏和一个位于其上方的 WebView,它填充了剩余的高度。现在我想向下滑动工具栏以隐藏它,并且在它动画时 webview 高度应该扩展。我尝试过使用 TranslateAnimation,但不幸的是它没有调整工具栏的实际位置,只是移动了它的内容。这是我尝试过的:
<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);
我该怎么做?
I have a toolbar aligned at the bottom and a WebView above it, which fill remaining height. Now I want to slide down the toolbar in order to hide it, and while it's animating the webview height should expand. I've tried using TranslateAnimation but unfortunetely it's not adjusting toolbar's real position, only it's contents are moved. Here's what I tried:
<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" />
And the actual code:
final View v = findViewById(R.id.browseToolbar);
Animation animation = AnimationUtils.loadAnimation(someContext, R.anim.toolbar_hide);
v.startAnimation(animation);
How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我编写了一些代码来执行实际的调整动画大小。看一下:
http://www.touchlab.co/blog/resize-animation/
另请参阅我针对 Android 动画所做的演示
https://docs.google.com/present/view?id=djqv5kb_187c62jvbf7
本质上,如上所述,常规动画类仅影响其父视图中的内容。理解它们的关键是它们不是“真实的”。将 Android 动画视为海市蜃楼。如果您运行我创建的示例应用程序,假设您执行缩放动画并使按钮变小,如果您单击按钮原来所在的外部,它仍然会注册为按钮单击。 Android 动画实际上并不影响真实的边界和尺寸。
我的博客文章中的代码本质上是实现 ViewGroup.OnHierarchyChangeListener。当从层次结构中添加/删除内容时,容器会以动画方式进行物理调整大小。
I wrote some code to do actual resize animations. Take a look:
http://www.touchlab.co/blog/resize-animation/
Also look at a presentation I did on Android animation
https://docs.google.com/present/view?id=djqv5kb_187c62jvbf7
Essentially, as mentioned above, the regular animation classes only affect what's in their parent view. The key to understanding them is they aren't "real". Think of the Android animation as a mirage. If you run the example app I created, say you do a scale animation and make a button smaller, if you click outside, where the button USED to be, it still registers as a button click. Android animations don't actually affect real boundaries and dimensions.
What the code in my blog post does, essentially, is implement a ViewGroup.OnHierarchyChangeListener. When stuff is added/removed from the hierarchy, the container animates a physical resize.
当您使用 Android 动画时,仅视图的像素会发生移动。要实际移动视图,您需要向动画对象添加动画侦听器并重写 onAnimationEnd 方法。在该方法中,您需要以编程方式移动视图。
When you use android animation only the pixels of the view are shifted. To actually move the view, you will need to add an animation listener to the animation object and override the onAnimationEnd method. In that method you need to programatically move the view.