Android text view transition - android

I am new to android development. I want to create a splash screen with two text views. In this splash screen I want two transitions
1) Text View 1 transition from top to center
2) text View 2 transition from bottom to center
Both transitions should be performed at the same time
how to achieve this ?
Thanks,

Creat an xml file in your anim folder name bottom_to_top.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="2000"
android:fillAfter="true"
android:fromYDelta="100%p"
android:toYDelta="0%p" />
</set>
and your oncreat you add this
TextView textview= (TextView) findViewById(R.id.textview);
Animation bottomToTop = AnimationUtils.loadAnimation(this, R.anim.bottom_to_top);
textview.startAnimation(bottomToTop);
and from top to bottom animation
create an xml file by name top_bottom.xml in your anim folder
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="2000"
android:fillAfter="true"
android:fromYDelta="-100%p"
android:toYDelta="0%p" />
</set>
and place in java
TextView textview2= (TextView) findViewById(R.id.textview2);
Animation topTobottom = AnimationUtils.loadAnimation(this, R.anim.top_bottom);
textview2.startAnimation(topTobottom );
Hope this helps you

Related

how to android textview marquee getDuration?

I have time many try TextView marquee animation scroll
need marquee animation duration, finish Listener
plz help me...
marquee scroll time
marquee scroll finish point or interface listener
You can create animation and animation time like this in anim res/anim/marquee.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="-100%"
android:duration="10000"
android:repeatCount="infinite"
android:repeatMode="restart"
android:interpolator="#android:anim/linear_interpolator"/>
</set>
and call it where you are using your textView
TextView myTextView = (TextView) findViewById(R.id.myTextView);
Animation marquee = AnimationUtils.loadAnimation(this, R.anim.marquee);
myTextView.startAnimation(marquee);

How to add ImageView animation only in the ImageResource

I have an ImageView in my layout.
ImageButton ib = (ImageButton) findViewById(R.id.btn1);
ib.setImageResource(R.drawable.blue_3);
I want to have an animation only for R.drawable.blue_3 icon from left to right.
its is not possible to only add animation to resource image not to view.
Rather you can do it by:
1.Taking any Layout in place of ImageButton.
2.Add ImageButton in Layout and then,
3.Apply animation to ImageButton.
I things your problem is to manage background of ImageButton so as par above idea you can do it the same.
try this its work for me....!
make a folder in resource and name it anim and place this xml file
(note: this is a sample xml file if you want single move you want to edit it)
move.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator" >
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-75%p"
android:toXDelta="75%p"
android:duration="2000" >
</translate>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="800"
android:fromXDelta="75%p"
android:toXDelta="-75%p"
android:duration="2000" >
</translate>
</set>
Finally add this in your code
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.move);
Image.startAnimation(animation);

Fade animation - not constant behavior Android

I want to make a Fade Out and In Animation every time I click a button.
I started to check only the fade out and on the first click it seems the Fade Out works just fine. But when I click again the animation fade from top to bottom, making it look bad and cut.
The Animation:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="1000" />
</set>
The Code:
Animation fadeOut = AnimationUtils.loadAnimation(myActivity.this, R.anim.fade_out);
LinearLayout myBackground=(LinearLayout)findViewById(R.id.myBackground);
myBackground.setAnimation(fadeOut);
What am I missing? Thanks!
Make anim in following folder ris->anim->fade_anim.xml
Add below xml
<alpha
android:duration="2000"
android:fromAlpha="1"
android:toAlpha="0.0"
android:repeatCount="infinite"/>
Got to java class
//make animation object
final Animation myAnim = AnimationUtils.loadAnimation(getContext(), R.anim.bounce_anim);
myAnim.setRepeatMode(Animation.INFINITE);
//get View on which on you want to apply animation I am applying on imageView
mLayout.findViewById(R.id.imageView).startAnimation(myAnim);

Android tween animation blinks fast and doesn't work

I am trying to make a TextView scale and fade out. My TextView is inside a layout file that is included into my activity's layout with
<include android:id="#+id/hud" layout="#layout/hud" android:layout_alignParentBottom="true"/>
Now, I can apply a scale animation from within the Java code like this:
TextView multiplier = (TextView)findViewById(R.id.hudMultiplier);
ScaleAnimation s = new ScaleAnimation(1.0f, 3.0f, 1.0f,3.0f);
s.setDuration(5000);
multiplier.startAnimation(s);
And it works nicely, but I want that animation (and a bunch of others) from an xml file. So I made this file:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://shemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:pivotX="50%"
android:pivotY="100%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="10.0"
android:toYScale="10.0"
android:duration="5000"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="2000"
android:startOffset="2000">
</alpha>
</set>
I am trying to apply the animation with this code:
TextView multiplier = (TextView)findViewById(R.id.hudMultiplier);
AnimationSet an = (AnimationSet) AnimationUtils.loadAnimation(getApplicationContext(), R.anim.multiplier);
multiplier.startAnimation(an);
What happens now is that the TextView blinks for a fraction of a second and nothing actually happens.
I've tried:
removing the alpha animation - no change
removing the start offset - no change
change the animation with one from the android documentation - no change
change AnimationSet to Animation - no change
change getApplicationContext() to this, MyActivity.this - no change
change getApplicationContext() to null - kills the application
What am I missing?
The project is targeted at Android 1.6 and I'm testing in a 2.3 emulator.
This seems to make a difference, for me anyway!
Change shemas to schemas in the Set element.
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://shemas.android.com/apk/res/android"
android:shareInterpolator="false">
try this:
an = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);

Using fade in animation for a view

I want to have a View that initially is invisible and when I press a button, it becomes visible with a fade in animation. I'm using the AlphaAnimation for the fading effect. The problem is that if I make the view invisible the animation can't be seen.
Suppose you have an ImageView named imageView and an animation file your_fade_in_anim.xml inside your res\anim\ folder:
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.your_fade_in_anim);
// Now Set your animation
imageView.startAnimation(fadeInAnimation);
Your XML
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="[duration (in milliseconds)]"
android:repeatCount="infinite" />
</set>
Replace the brackets with your actual duration.
Provide an AnimationListener to the Animation and make the View visible as soon as the Animation starts.
http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html
Instead of the infinite repeat count and hiding/viewing your View, I suggest to just not repeat the animation and initially start with the alpha channel set to maximum. Then you can use:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="[duration (in milliseconds)]"
android:repeatCount="0" />
</set>
And you're done. No need for a Listener, hiding or showing. Just as simple.

Categories

Resources