Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Attribute for specifying pivotXType and pivotYType in ScaleAnimation

this may sound silly, but i can´t find anywhere how to specify the pivotXType and pivotYType of a ScaleTAnimation.

I know how to do it programatically, but i need to specify it via XML (i need it for transition between activities, using overridePendingTransition method)

Here´s the code that works:

 Animation animation=new ScaleAnimation(1,0,1,0,ScaleAnimation.RELATIVE_TO_SELF,(float)0.5,ScaleAnimation.RELATIVE_TO_SELF,(float)0.5);  
  animation.setDuration(1000);

Here´s the XML, without the XML attribute i´m looking for

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="1"
    android:toXScale="0"
    android:fromYScale="1"
    android:toYScale="0"
    android:pivotX="0.5"        
    android:pivotY="0.5"
    android:duration="2000"
    />

I checked out the documentation at http://developers.androidcn.com/reference/android/view/animation/ScaleAnimation.html, but didn´t find any answer. Thanks.

like image 473
molerus Avatar asked Jan 11 '11 17:01

molerus


2 Answers

Hope no one even bothered reading my question. I was making a mistake when writing the xml, here´s the correct code for the effect i wanted (scaling the new activity from 100% size to 0% size, right in the middle of the screen). Correct values for pivotX and pivotY are 50% instead of 0.5.

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="1"
    android:toXScale="0"
    android:fromYScale="1"
    android:toYScale="0"
    android:pivotX="50%"        
    android:pivotY="50%"
    android:duration="600"
    />
like image 115
molerus Avatar answered Sep 28 '22 07:09

molerus


I know the answer has been already posted, but I thought I would write a few words of explanation. Pivots in xml can be set to three types of values (example using value 50):

  • 50% - percentages; Corresponding to the type of pivoting Animation.RELATIVE_TO_SELF. 50% basically means that it will pivot in the middle of the view.

  • 50%p - parent percentages; Corresponding to the type of pivoting Animation.RELATIVE_TO_PARENT. 50%p means that it will pivot in the middle of the parent view.

  • 50 - absolute; Corresponding to the type of pivoting Animation.ABSOLUTE. 50 means pivoting at the 50 pixels from the top/left (depends on the type of pivot - y/x)

like image 42
Bartek Lipinski Avatar answered Sep 28 '22 06:09

Bartek Lipinski