how to android textview marquee getDuration? - android

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);

Related

i want implement animation for Floating Button

I want to give a full rotation animation to my floating button, i have the code, but its only animating like rotating half. i want rotate the floating button from a position and it should end with the same position where it started( a full rotation ) , how to do that ?
here is my code , i want some one to modify the value or code
final OvershootInterpolator interpolator = new OvershootInterpolator();
ViewCompat.animate(fab).
rotation(170f).
withLayer().
setDuration(1000).
setInterpolator(interpolator).
start();
Make rotate.xml in res/anim:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="0"
android:duration="1000" />
</set>
Then in code:
FloatingActionButton mFloatingButton = view.findViewById(R.id.myFloatingButton);
Animation mAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
mFloatingButton.startAnimation(mAnimation);

Android text view transition

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

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