我有通常在两个活动之间放大和缩小动画的代码,但我想要一些不同的东西。如果我单击第一个按钮,那么我的第一个活动有五个按钮,然后放大将仅从第一个按钮的位置开始,而不是从中心放大。请帮我。
编辑:缩放应该从我单击的按钮开始。
我有通常在两个活动之间放大和缩小动画的代码,但我想要一些不同的东西。如果我单击第一个按钮,那么我的第一个活动有五个按钮,然后放大将仅从第一个按钮的位置开始,而不是从中心放大。请帮我。
编辑:缩放应该从我单击的按钮开始。
您可以在运行命令后使用此方法启动新活动,
startActivity(intent);
overridePendingTransition(animation_in_goes_here,animation_out_goes_here);
然后您可以替换上面的动画,将 替换animation_in_goes_here
为您新启动的活动所需的animation_out_goes_here
动画资源,并替换为您要离开的活动的动画资源。这将为您提供切换效果。
zoom_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3"
android:toYScale="3"/>
</set>
zoom_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<scale
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5"/>
</set>
希望这有助于回答您的问题。
放大
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="0"
android:fromYScale="0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5">
</scale>
缩小
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="2.1"
android:fromYScale="2.1"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="3000"
android:toXScale="0"
android:toYScale="0">
</scale>
I think you have to do as follow
Put animation descriptions into res/anim folder
object.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.zoom_enter));
object.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.zoom_exit));
You can use android sdk sample animations supplied by google under Apache 2.0 licence
Or refer this which uses scaling based zooming which is easier than the former