2011-12-29 4 views
2

У меня есть эта анимация:Изменить XML Animation андроид динамического кода

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/decelerate_interpolator"> 
    <scale android:fromXScale="1.0" android:toXScale="2.0" 
    android:fromYScale="1.0" android:toYScale="2.0" 
    android:pivotX="50%p" android:pivotY="50%p" 
    android:duration="2000" /> 
</set> 

Но я должен сделать это динамичным в моем коде:

AnimationSet animSet = new AnimationSet(false); 
animSet.setInterpolator(AnimationUtils.loadInterpolator(AddPhoto.this, 
    android.R.anim.decelerate_interpolator)); 
ScaleAnimation zoom = new ScaleAnimation(1.0f, 1.0f, 2.0f, 2.0f); 
    zoom.setDuration(2000); 
    animSet.addAnimation(zoom); 

Но это не то же самое, что я сделал неправильно? Благодарю.

ответ

4

Вы забыли установить PivotX и PivotY. Используйте следующий конструктор ScaleAnimator

public ScaleAnimation (float fromX, float toX, float fromY, float toY, 
         float pivotX, float pivotY) 


Parameters 

fromX Horizontal scaling factor to apply at the start of the animation 
toX Horizontal scaling factor to apply at the end of the animation 
fromY Vertical scaling factor to apply at the start of the animation 
toY Vertical scaling factor to apply at the end of the animation 
pivotX The X coordinate of the point about which the object is being scaled, 
      specified as an absolute number where 0 is the left edge. (This point 
      remains fixed while the object changes size.) 
pivotY The Y coordinate of the point about which the object is being scaled, 
      specified as an absolute number where 0 is the top edge. (This point 
      remains fixed while the object changes size.) 

 Смежные вопросы

  • Нет связанных вопросов^_^