Android的动画正在添加视图到屏幕,将当前全屏显示出来 [英] Android animate view comming into screen that pushes the current full screen view out

查看:341
本文介绍了Android的动画正在添加视图到屏幕,将当前全屏显示出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这一个项目pre API11。

I need this for a project pre API11.

进出口寻找一种方式来从右侧添加视图,这将导致目前的全屏视图搬出到左,允许新视图在屏幕上visibe。

Im looking for a way to add a view in from right, that will cause the current full screen view to move out to left as to allow the new view to be visibe in the screen.

新的观点是屏幕宽度的1/3左右因此多数民众赞成在距离当前fusll屏幕视图应该迁出的画面。

the new view is about 1/3 of the screen width so thats the distance the current fusll screen view should move out of the screen.

我有TranslateAnimation()累了各种解决方案,但我很高兴与动画,我在与原认为不是,他们都应该是所有的可点击区域的问题。

i have tired various solutions with TranslateAnimation(), although im happy with the animation, i'm having issues with all the clickable areas in the original view not being where they are supposed to be.

所以我开始布局打负利润率正确定位,但是当一个新的布局请求到来几秒钟后视图弹出回原位。同时该解决方案具有移动的动画结束监听器视图时波涛汹涌的效果。

so i started playing with the layout to position it correctly with negative margin, but after a couple of seconds when a new layout request comes the view is popped back into place. also this solution had a choppy effect when moving the view on the animation end listener.

这将是一个最简单的解决方案,具有在新的视图进入或退出,并在布局方面的投入认为在正确的位置好的动画。

what would be the most simple solution that has good animation when the new view is entering or exiting and that puts the view in the correct place in terms of layout.

推荐答案

由于您使用的API11,使用的动画API 。所有视图现在有性能与相应的getter和setter方法​​。到视图左移超出范围,得到了屏幕的宽度然后执行:

Since you're using API11, use the Animator API. All views have properties now with corresponding setters and getters. To shift a view to the left out of scope, get the width of the screen then do:

View viewToShiftOut = getOutView();
ObjectAnimator outAnim = ObjectAnimator.ofFloat(viewToShiftOut, "x", 0, -widthOfScreen);
outAnim.setDuration(1000);
outAnim.start();

这将转向视图,它的内容完全脱离了屏幕的1秒(1000毫秒)的持续时间。在它的地方转变之一进行:

This will shift the view and it's contents entirely out of the screen for a duration of 1 second (1000 miliseconds). To shift one in it's place do this:

View viewToShiftIn = getInView();
ObjectAnimator inAnim = ObjectAnimator.ofFloat(viewToShiftIn, "x", widthOfScreen, 0);
inAnim.setDuration(1000);
inAnim.start();

所有的属性,可点击区域等将按照视图,所以你的时候完成的动画来完成。你们可以一起为它们制作动画,像这样:

All the properties, clickable areas, etc. will follow the view so you'll be done when the animations finish. You can animate them together like so:

View viewToShiftOut = getOutView();
View viewToShiftIn = getInView();
ObjectAnimator outAnim = ObjectAnimator.ofFloat(viewToShiftOut, "x", 0, -widthOfScreen);
ObjectAnimator inAnim = ObjectAnimator.ofFloat(viewToShiftOut, "x", widthOfScreen, 0);
outAnim.setDuration(1000);
inAnim.setDuration(1000);
outAnim.start();
inAnim.start();

博客文章

编辑:我注意到你想只用1/3的一个视图切换,这样你就可以得到像素移位每个量 widthOfScreen / 3

I noticed you wanted to only shift the view by a 1/3rd, so you can get the amount of pixels to shift each by widthOfScreen/3.

编辑2:另一个好处是你可以用硬件加速使用它,而其中大部分3.0+平板电脑有麻烦

EDIT 2: Another advantage is you can use it with hardware acceleration without trouble which most 3.0+ tablets have.

这篇关于Android的动画正在添加视图到屏幕,将当前全屏显示出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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