Android slide animation - java

Why I am not able to slide text view in android from right to left continuously?
I am using below xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="-3%p"
android:toXDelta="3%p"
android:duration="1200" />
</set>

If you want your animation to play continuously, you need to add the following two attributes to "translate" tag.
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="-3%p"
android:toXDelta="3%p"
android:duration="1200"
android:repeatCount="infinite"
android:repeatMode="reverse"/>
</set>
Note that if “repeatCount" and "repeatMode" are added to "set" tag, things will not work as expected.

Related

Need to create an xml file (R.anim) that defines a pendulous movement in Android

I would not like to reinvent the wheel (or the pendulum) here.
I have found samples of xml code to perform most of the animations in my project.
Examples (from https://www.androidhive.info/2013/06/android-working-with-xml-animations/ )
slide_up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="#android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
bounce.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="#android:anim/bounce_interpolator">
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
etc...
I'm now looking for a pendulous movement using a similar format so I can run this command to
simulate the action of shuffling a card deck:
shuffleCard = AnimationUtils.loadAnimation(this, R.anim.pendulous);
I solved it using the common rotation movement, but I set the pivotX and pivotY to a distant center, and reducing toDegrees to 20:
pendulous.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0"
android:toDegrees="20"
android:pivotX="50%"
android:pivotY="150%"
android:duration="600"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="#android:anim/cycle_interpolator"/>
</set>

Liquid level animation( Battery Doctor )

I want to know how to make this kind of animation in android ( The same in Battery Doctor app ).
I found a way to do this using two green images with an oppacity of 50% one behind the other and another one on the front to hide the unwanted content ( The circle ),I animate the first green image by XML using the code below
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="1850"
android:fromDegrees="-4"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:interpolator="#android:anim/linear_interpolator"
android:toDegrees="4" />
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="1"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:interpolator="#android:anim/linear_interpolator"
android:duration="1500" />
</set>
And the second green one by using this:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="1800"
android:fromDegrees="-1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:interpolator="#android:anim/linear_interpolator"
android:toDegrees="1" />
<translate
android:fromXDelta="80"
android:toXDelta="-4"
android:fromYDelta="-1"
android:toYDelta="1"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:interpolator="#android:anim/linear_interpolator"
android:duration="1500" />
</set>
But how can I create the view programatically ?I want to set the level dynamically from code. for example myView.setLevel(45);
I have finally found a library: WaveView
https://github.com/john990/WaveView
Edit
This library https://github.com/gelitenight/WaveView also does the same thing with more features. You can :
Shift the wave horizontally.
Set water level.
Set vertical size of wave.
Set horizontal size of wave.

simple in and out animation with android

i have some questions to the animations on android:
first of all, does someone have good links to sites where animations for android get explained? Only XML-Animations please, i dont want to use java-code for the animations..
The second question: I want to simply animate the activity from tight to left when it comes up and from left to right when it goes, but i can't achieve this simple animation.
My XML Files look like this:
push left in:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="#android:integer/config_shortAnimTime"
android:fromXDelta="-100%p"
android:toXDelta="0" />
<alpha
android:duration="#android:integer/config_shortAnimTime"
android:fromAlpha="1.0"
android:toAlpha="1.0" />
</set>
push right out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="#android:integer/config_shortAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p" />
<alpha
android:duration="#android:integer/config_shortAnimTime"
android:fromAlpha="1.0"
android:toAlpha="1.0" />
</set>
In my code i use: overridePendingTransition(R.anim.push_left_in,R.anim.push_right_out); and overridePendingTransition(R.anim.push_right_out,R.anim.push_left_in); after the super.finiah();
This is how I set up a simple fade in, fade out animation
Here's my incoming.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator" >
<alpha
android:duration="#android:integer/config_mediumAnimTime"
android:fromAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
Here's my outgoing.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator" >
<alpha
android:duration="#android:integer/config_mediumAnimTime"
android:fromAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
And here's how I call set the animation in my activity
Intent i = new Intent(this, ABCActivity.class);
startActivity(i);
ModeSelectActivity.this.overridePendingTransition(
R.anim.outgoing, R.anim.incoming);
Also, be sure to override onBackPressed() for the reverse animation
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
ModeSelectActivity.this.overridePendingTransition(R.anim.outgoing,
R.anim.incoming);
}
You have many animations on this page:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.5_r1/frameworks/base/core/res/res/anim/
You can look at slide_in_left.xml,slide_in_right.xml, slide_out_left.xml and slide_out_right.xml.
You can use these transitions with overridePendingTransition().

ViewFlipper in Fragment (TabHost) child not shown until touch on it

I have a Tab (suing Fragments) and the Tab content is actually a View Flipper.
The first page of the Flipper shows list of images. When I click to some of the items I go to Flipper's page 2. Which will show the image in Full Screen. When I click Back it goes to the List View (with all images). Everything works as expected until I put in and out animations to the ViewFlipper. After I set in Animation to be some Translate animation, I see nothing, until I touch the screen. When I touch the screen I see the image, and if not, I see empty tab content.
I am using ViewFlipper and Fragments from the support package.
Is this some sort of expected behavior or an issue?
ADDED ANIMATIONS
left_to_right_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="700"
android:fromXDelta="-220%"
android:fromYDelta="0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toXDelta="0"
android:toYDelta="0" />
</set>
left_to_right_out.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="700"
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toXDelta="220%"
android:toYDelta="0" />
</set>
right_to_left_in.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="700"
android:fromXDelta="220%"
android:fromYDelta="0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toXDelta="0"
android:toYDelta="0" />
</set>
right_to_left_out.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="700"
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toXDelta="-220%"
android:toYDelta="0" />
</set>
And then I use them like this:
When I want to show the second child of the view flipper:
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.left_to_right_in));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.left_to_right_out));
mViewFlipper.showPrevious();
When I want to go back to the first child:
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.right_to_left_in));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.right_to_left_out));
mViewFlipper.showNext();

Avoid Blank Screen while transitioning Activity Screen

I have Two Activities A and B
A is starting B like
Intent i = new Intent();
i.setClass(A.this, B.class);
startActivity(i);
overridePendingTransition(R.anim.right_slide_in, R.anim.down_slide_out);
finish();
where
R.anim.right_slide_in is
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:fromXDelta="+100%p"
android:toXDelta="0"
android:duration="700"
/>
</set>
and
R.anim.down_slide_out is
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
<translate
android:fromYDelta="0"
android:toYDelta="+100%p"
android:duration="700" />
</set>
This work great. B comes sliding from right and A goes out sliding down.
Problem is during this transition. A Blank Screen appears as background of whole app
How to avoid that ?
Any help would be appreciated
Try using an application theme (e.g., <application android:theme="#style/MyTheme">) that sets the android:windowBackground attribute to a drawable, such as:
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowBackground">#drawable/app_background</item>
</style>
</resources>
Not Possible As far As Application Layer is Concerned.
Try this.
move_to_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="#android:anim/linear_interpolator" >
<translate
android:duration="800"
android:fromXDelta="100%p"
android:toXDelta="0%p" />
</set>
move_to_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="#android:anim/linear_interpolator" >
<translate
android:duration="800"
android:fromXDelta="0%p"
android:toXDelta="-100%p" />
</set>
startActivity(recipeCategoriesIntent);
overridePendingTransition(R.anim.move_to_left, R.anim.move_to_right);

Categories

Resources