I have a anim resource which scrolls TextView (credits screen).
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="50000"
android:fromYDelta="200"
android:interpolator="#android:interpolator/linear"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toYDelta="-10000" />
</set>
I want to have constant transision speed with zero acceleration (same velocity over the whole animation period). I cannot find android:interpolator value that would allow that. Without android:interpolator value translate still uses some sort of acceleration profile.
Try using #android:anim/linear_interpolator for the interpolator.
Source containing list of available xml resources corresponding to common animators: http://developer.android.com/guide/topics/resources/animation-resource.html#Interpolators
Related
Hi I have a problem with controlling position of my object on the screen. When I create activity every object on the screen is placed with animation and troubles starting here. Firstly I tried to placed all things with pixel coordinates, which based on height and width of screen. I want to take it from device when activity starts. During the coding I think the better way will be use the % values cause I don't need to think about diferent screen resolution and stuff like this.
The picture shows, how I thought the screen looks with different values,but I'm wrong.I make the assumption, that the layout match to the parent, so it have nearly this same size as the screen
Cause the range of values for % and %p is from -100 to 100, so where is -100%, when I put something like -60%p I can't see it on the screen. I try to play with the object by changing the values and see results, but for example
object represented by
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true"
android:duration="3000"
android:startOffset="7000">
<translate
android:fromXDelta="2600"
android:toXDelta="0%p"
android:fromYDelta="-10"
android:toYDelta="-10%p"
/>
<rotate
android:fromDegrees="359"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
/>
is higher on the screen then object represented by:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true"
android:duration="3000"
android:startOffset="12000">
<rotate
android:fromDegrees="359"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
/>
<translate
android:fromXDelta="-599"
android:toXDelta="40%p"
android:fromYDelta="-499"
android:toYDelta="-10%p"
/>
I think they should be on this same vertical level, because android:toYDelta is the same.
When we are putting the values to xml code, we are placing the right top corner of the object in my opinion.
Please clear the way I think about coordinates of different type, and where are mistakes?
I would be grateful for every answer.
I have a transition from one activity to another that I am using in overridePendingTransition. Unfortunately all overridePendingTransition uses is the resource id of the file, so I am having trouble about how to edit this file so my transitions are proper.
Basically what I need to do is make changes to the R.anim.flip_in_scale_in so that I can change the value of the transitions fromX/toX so that it is set based on the user's screen size.
overridePendingTransition(R.anim.flip_in_scale_in, R.anim.stationary_item);
How do I update the R.anim.flip_in_scale_in file before use in the overridePendingTransition?
There isn't a way you can alter the animation from the resource file in the way you want.
However, you CAN create the animation to use percentages rather than dp values. When the animation is applied to the Activity's View, it will animate entirely on the view's size (which in most cases is the screen size).
This for example:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
android:duration="500"
/>
</set>
Will slide in the view from the right side to the screen within half-a-second.
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.4"
android:fromYScale="1.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000" />
</set>
This will increase the view to 40% it's current size over the span of one second. The pivot will be directly in the middle of the view regardless of the view's size.
I in my Android Honeycomb application there is a View which has a fade in and fade out animation. Here's most part of the animation code:
<scale
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="0%"
android:pivotY="0%"
android:duration="500" />
The way it's working right now the animation happens in a linear time but I want to do it according the Cosine function, that is from Cos(0) until Cos(0,5*pi) the fade out case.
Is it possible to do such thing?
Thank you.
You are free to create your own Interpolator. (See the interface description here.) This can then be applied with Animation.setInterpolator(Interpolator). Or, see this discussion for ways of applying custom Interpolators in XML.
If you don't want linear interpolation, you have choice between:
AccelerateDecelerateInterpolator, AccelerateInterpolator,
AnticipateInterpolator, AnticipateOvershootInterpolator,
BounceInterpolator, CycleInterpolator, DecelerateInterpolator,
LinearInterpolator, OvershootInterpolator
http://developer.android.com/reference/android/view/animation/Interpolator.html
So maybe what is the closest to a Cosine is:
AccelerateDecelerateInterpolator
An interpolator where the rate of change starts and ends slowly but
accelerates through the middle.
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.
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"
/>
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)
I want to rotate a button about X-axis when clicked and then display a different image so it creates an effect that after button click it's flipping and showing a different image which is at its backside.
I'm using following xml for rotation of button:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<set android:interpolator="#android:anim/decelerate_interpolator">
<rotate
android:fromDegrees="0"
android:toDegrees="-360"
android:pivotX="25%"
android:pivotY="25%"
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="0"
android:duration="400" />
</set>
</set>
But it's rotating the button in 2-D plane about the button's center.
I have a flip example here:
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
I'm afraid the conventional graphics and animation APIs are 2D. To use that 3rd dimension you'd need to look into OpenGL, which is non-trivial.
You might be able to fake a depth effect by writing a custom animation that uses setPolyToPoly to warp your initial rect into a trapezoid.
It's been a while since this question is posted, but just for the record - there is a way in newer versions of android, and for back compatibility use http://nineoldandroids.com/