How to make the textview blinking

前端 未结 11 2059
谎友^
谎友^ 2020-12-02 09:14

Guys i have a textview which i need it to be blinking please help me with it.



        
相关标签:
11条回答
  • 2020-12-02 09:41

    Just use the <blink/> tag.

    <blink
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
    
      <TextView 
           android:id="@+id/usage"
           android:layout_marginTop="220dip"
           android:layout_marginLeft="45dip"
           android:layout_marginRight="15dip"
           android:typeface="serif"            
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Google "
           android:textColor="#030900"/>
    
    </blink>
    
    0 讨论(0)
  • 2020-12-02 09:43

    You can make an animation or maybe why not making it View.VISIBLE and View.INVISIBLE with a timer? I think the better way is the animation with alpha indeed :)

    0 讨论(0)
  • 2020-12-02 09:52

    Use XML Animations for this purpose :

    R.anim.blink

    <?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="600"
            android:repeatMode="reverse"
            android:repeatCount="infinite"/>
    </set>
    

    Blink Activity: use it like this :-

    public class BlinkActivity extends Activity implements AnimationListener {
    
        TextView txtMessage;
        Button btnStart;
    
        // Animation
        Animation animBlink;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_blink);
    
            txtMessage = (TextView) findViewById(R.id.txtMessage);
            btnStart = (Button) findViewById(R.id.btnStart);
    
            // load the animation
            animBlink = AnimationUtils.loadAnimation(this,
                    R.anim.blink);
    
            // set animation listener
            animBlink.setAnimationListener(this);
    
            // button click event
            btnStart.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    txtMessage.setVisibility(View.VISIBLE);
    
                    // start the animation
                    txtMessage.startAnimation(animBlink);
                }
            });
    
        }
    
        @Override
        public void onAnimationEnd(Animation animation) {
            // Take any action after completing the animation
    
            // check for blink animation
            if (animation == animBlink) {
            }
    
        }
    
        @Override
        public void onAnimationRepeat(Animation animation) {
    
        }
    
        @Override
        public void onAnimationStart(Animation animation) {
    
        }
    
    }
    

    Let me know if you have any queries..

    0 讨论(0)
  • 2020-12-02 09:54

    Here is my helper implementation using an alpha animation:

        public void blinkText(final TextView text_to_animate, int durationMillis) {
    
            final AlphaAnimation fade_out = new AlphaAnimation(1.0f, 0.0f);
            //ScaleAnimation scale_it = new ScaleAnimation(1.0f, 1.25f, 1.0f, 1.25f);
            fade_out.setDuration(durationMillis);
    
            final AlphaAnimation fade_in = new AlphaAnimation(0.0f, 1.0f);
            //ScaleAnimation scale_it = new ScaleAnimation(1.0f, 1.25f, 1.0f, 1.25f);
            fade_in.setDuration(durationMillis);
    
            fade_out.setAnimationListener(new AnimationListener() {
                public void onAnimationEnd(Animation arg0) {
                    // TODO Auto-generated method stub
                if (recording == true)
                    text_to_animate.startAnimation(fade_in);
                }
                public void onAnimationRepeat(Animation arg0) {
                    // TODO Auto-generated method stub              
                }
    
                public void onAnimationStart(Animation arg0) {
                    // TODO Auto-generated method stub              
                }
    
            });
    
            fade_in.setAnimationListener(new AnimationListener() {
                public void onAnimationEnd(Animation arg0) {
                    // TODO Auto-generated method stub
                    if (recording == true)
                        text_to_animate.startAnimation(fade_out);
                }
                public void onAnimationRepeat(Animation arg0) {
                    // TODO Auto-generated method stub              
                }
    
                public void onAnimationStart(Animation arg0) {
                    // TODO Auto-generated method stub              
                }
    
            });
    
            text_to_animate.startAnimation(fade_out);       
    
        }
    
    0 讨论(0)
  • 2020-12-02 09:55

    Don't need set for this. Just alpha:

    anim/flash_leave_now.xml

        <?xml version="1.0" encoding="utf-8"?>
        <alpha xmlns:android="http://schemas.android.com/apk/res/android"
           android:duration="900"
           android:fromAlpha="1.0"
           android:repeatCount="infinite"
           android:repeatMode="reverse"
           android:toAlpha="0.2"/>
    

    And in code:

    mTextView.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.flash_leave_now));
    
    0 讨论(0)
提交回复
热议问题