Animation to move view with 200dp upside/downside - android

I want to make animation to move layout exactly 200 dp up for android application. So far I tryed many ways and cannot make it to work on multiple screen sizes.
This is xml file that im using:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:fillAfter="true"
android:interpolator="#android:anim/linear_interpolator"
android:duration="10000"
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="-400" />
</set>
I tried this also
final TranslateAnimation moveUpAnimation = new TranslateAnimation(0, 0, dpAsPixels, 0);
dissapearAnnimation.setDuration(20000);
The problem is that this layout has dinamic content so its lenght is changing, so % of its lenght to move up is not working for me . Thanks in advancce !

Take a look at ViewPropertyAnimator.
yourView.animate().translateY(getResources().getDimensionPixelSize(R.dimen.animationHeight)).setDuration(yourDurationInMs);
In your dimension resources:
<dimen name="animationHeight">-200dp</dimen>

What kind of layout are you using? To animation you sholdu use relative / frame layouts.

Related

Android Translation animation

i am trying to animate an image view by ensuring that the object appears in the center of the screen and then translates up.. to its final position. the code i used is as follows.
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:fromYDelta="400"
android:toYDelta="0"
android:duration="800"/>
</set>
This code works when u have a device of 4.7"(galaxy s3) screen size the image will appear at the center of the screen and then move to its set position. But on a screen of 4" (S advance or htc desire x) the image practically appears at the screen bottom.
So is there any way to ensure that the image is at the center of the screen heedless of the device on which the code is running?? Thanks in advance..
Use percentages instead of values to make the Animation uniform across all screen sizes.
The animation should apply its transformation after it ends
android:fillAfter="true"
The animation begins from the vertical center, i.e 50% of Y
android:fromYDelta="50%p"
The animation ends at the top, i.e. 0% of Y
android:toYDelta="0%p"
XML:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="800"
android:fillAfter="true"
android:fromYDelta="50%p"
android:toYDelta="0%p" />
</set>
thanks for ur response..
i tried ur suggestion 's and i found that using 50%p to then in a 4 inch screen the image view is present at around 3\4of the screen. but when i use 25%p then its around the center. in case of s advance its center and in s3 its relatively center.. i guess it depends on the size of the image.(dimention)

Android - Alter animation in resource file

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.

want a ImageView to come from upside down

i have a window and a imageview in it and i want the imageview to come from upside down animated effect how i do that
ImageView img_sliding=(ImageView)findViewById(R.id.img_sliding);
You have to write your own translate animation. a very good tutorial could be found here..
Here is a litte snipped that you can use and adapt it to your needs:
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%"
android:toYDelta="0%"
android:duration="300"
android:zAdjustment="top"
android:fillAfter="true" />
create a new xml file in res/anim and then set the animation to your imageview like this:
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.YOURANIMATION)
and set it to the iamgeView
imageview.setAnimation(anim);
Use a scale animation to scale from -1 to 1. This should have the effect of flipping the imageview

Rotate button about X-axis in an Android app

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/

Scale & Translate animation

I require an animation for an image in my application.
The image should start coming from the top left corner till the middle of screen. The image size will be smaller at the initial stage. While coming to the middle of the screen, its size should increase(i.e. scaling should take place). Image should not go back to its original position. It should be placed at the middle of the screen itself after the animation.
Can anyone please help.
Please find the answer here.
Create an xml inside /res/anim folder and put the below code into it.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<scale android:fromXScale="0.0" android:fromYScale="0.0"
android:toXScale="1.0" android:toYScale="1.0"
android:duration="700" android:fillBefore="false" />
<translate android:fromXDelta="-200" android:fromYDelta="-200"
android:duration="700" />
</set>
Place the below code inside the java file:
Animation logoMoveAnimation = AnimationUtils.loadAnimation(this, R.anim.logoanimation);
logoIV.startAnimation(logoMoveAnimation);
logoanimation is the name of my animation xml file.
Thanks for all those who tried out for my question.

Categories

Resources