java - How to apply Blink animation or effect on old android devices? -


i used code posted below blink animation, code still buggy , if user click 2 times on button, blink becomes faster. stopping thread not effective.

boolean mythreadalive = false; private void blink(final view txt){      if(mybestthread != null){         if(!mythreadalive) {             mythreadalive = false;             if (mybestthread.isalive()) {                  mybestthread.interrupt();                 try {                     mybestthread.join();                 } catch (interruptedexception e) {                 }             }         }     }      mybestthread = new thread(new runnable() {         @override         public void run() {             final int timetoblink = 1000;    //in milissegunds             mythreadalive= true;             while(mythreadalive) {                 try {thread.sleep(timetoblink);}catch(exception e){}                 handler.post(new runnable() {                     @override                     public void run() {                         if (txt.getvisibility() == view.visible) {                             txt.setvisibility(view.invisible);                         } else {                             txt.setvisibility(view.visible);                         }                     }                 });             }             handler.post(new runnable() {                 @override                 public void run() {                     txt.setvisibility(view.visible);}});         }     });     mybestthread.start(); } 

any other solutions please?

you can use animation class achieve effect create anim folder in res directory if not , create blink.xml file

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"     android:fillafter="true">     <alpha         android:fromalpha="0.0"         android:toalpha="1.0"         android:duration="100"         android:repeatcount="infinite"         android:interpolator="@android:anim/accelerate_interpolator"         /> </set> 

and in jave whatever want animate call

  animation anim=animationutils.loadanimation(getapplicationcontext(),r.anim.blink);   textview.startanimation(anim); 

just call these line inside onclick or whenever want animation start in blink.xml can change duration make animation slow or fast


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -