TextView Text Size Animation

I want to be able to do text animation and resize text in a TextView. I read that there is an animation of properties in android, but if someone knows a simple code that can do this for me or for an example, I will be deeply grateful to that. Thanks in advance!

+9
source share
5 answers

scale.xml

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="2.0" android:toYScale="2.0" android:duration="3000"></scale> </set> 

Function in Activity:

 private void RunAnimation() { Animation a = AnimationUtils.loadAnimation(this, R.anim.scale); a.reset(); TextView tv = (TextView) findViewById(R.id.firstTextView); tv.clearAnimation(); tv.startAnimation(a); } 

extracted and modified from here

+17
source
 Animation animation=new TranslateAnimation(0,480,0,0); animation.setDuration(5000); animation.setRepeatMode(Animation.RESTART); animation.setRepeatCount(Animation.INFINITE); text.startAnimation(animation); // applying animation to textview object.. 

If you use a button event to show the animation, then put the code inside onClick (), otherwise use the onWindowFocusChanged (boolean hasFocus) override method to start the animation

+6
source

How about this link ? In particular, examples of the scale. It provides source code and video for several different types of Android animations.

+3
source

Use the ValueAnimator class in android

 final float startSize = o; // Size in pixels final float endSize = 30; final int animationDuration = 1000; // Animation duration in ms ValueAnimator animator = ValueAnimator.ofFloat(startSize, endSize); animator.setDuration(animationDuration); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float animatedValue = (float) valueAnimator.getAnimatedValue(); tv.setTextSize(animatedValue); } }); animator.start(); 

link to this link ValueAnimator

Another solution is to use scaling animations in Textview or its parent layout.

 ScaleAnimation scaleAnimation = new ScaleAnimation(0.7f, 1.1f, 0.7f, 1.1f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(600); viewZoom.startAnimation(scaleAnimation); 
+3
source

I searched for the same thing, and found out with Kotlin, this can be done like this using the Kotlin extension function.

0
source

Source: https://habr.com/ru/post/898780/


All Articles