Text animation from left to right, like glitter in Android

I donโ€™t know what type of animation he called, but I want to implement it as shown below. I saw this animation on iOS.

enter image description here

As you can see, the offer slide for cancellation will animate from left to right, as if there was a light behind it.

I do not know what to use. I tried some kind of animation, for example Alpha, but I can not achieve this. Can anybody help me?

+6
source share
5 answers

This is my demo, please try

https://github.com/FrankNT/TextViewSlideEffect

Regards, Frank

Text Animation from left to right like shine in Android

+6
source

Get a solution using Spannable

The following is the Thread class, which runs continuously at intervals of 100 ms.

class MyThread extends Thread { //used for stopping thread boolean flag; //init flag to true so that method run continuously public MyThread() { flag = true; } //set flag false, if want to stop this thread public void setFlag(boolean flag) { this.flag = flag; } @Override public void run() { super.run(); while (flag) { try { Thread.sleep(intervalMiliSeconds); runOnUiThread(new Runnable() { @Override public void run() { Spannable spn = new SpannableString(txtView .getText().toString()); spn.setSpan(new ForegroundColorSpan(Color.WHITE), startPosition, endPosition, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); txtView.setText(spn); startPosition++; endPosition++; endPosition %= (lengthOfString + charGaps); startPosition %= lengthOfString; if (startPosition == 0) { endPosition = charGaps; startPosition = 0; } if (endPosition > lengthOfString) { endPosition = lengthOfString; } Log.d("Home", "Start : " + startPosition + " End : " + endPosition); } }); } catch (Exception e) { e.printStackTrace(); } } } } 

To use the above code, use the following implementation.

 TextView txtView = (TextView) findViewById(R.id.txtView); int charGaps = 3; int startPosition = 0; int endPosition = charGaps; int lengthOfString = txtView.getText().length(); MyThread thread = new MyThread(); thread.start(); 

Output

enter image description here

Even better answers will be more valuable. :)

+4
source

Here is another text slide effect using iOS,

https://github.com/RomainPiel/Shimmer-android

+4
source

I think you are talking about the Shimmer effect. Facebook made a library for this. This will help you show the glow effect from left to right with many additional options.

Here you can see the full documentation. Shimmer library

+1
source

You have 2 ways:

1) when working with openGL and we use shaders to make this effect.

2) Create a layer above the text that contains the [transparent] [white] [transparent] gradient and animates it.

0
source

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


All Articles