Cómo hacer que la vista de texto parpadee
Chicos tengo un textview que necesito que parpadee por favor me ayude con él.
<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"/>
Quiero que el texto de google esté parpadeando
- Android TextView: "No concatenar el texto mostrado con setText"
- Cómo cambiar entre 2 lugares TextViews en el diseño?
- TextView funciona mal con breakStrategy = "equilibrado" y layout_width = "wrap_content"
- Cómo deshabilitar el TextView maxLines mediante programación?
- Cómo cambiar el color de las palabras con hashtags
- Altura de línea de Android Spannable
- Paginación de texto en Android
- Cómo alinear verticalmente texto en un TextView con Compound Drawable
- Dpi valor de "grandes", "medio" y "pequeño" vistas de texto android
- Añadir http: // www. En el texto si no existe
- Cambiar el tamaño de los diferentes caracteres en la vista de texto, Android
- TextView android: ellipsize = "end" issue
- Cómo iniciar la barra de acción contextual para ver el texto de forma programática con opions por defecto copiar y seleccionar todo?
Es una respuesta obsoleta a Android antes de la versión 3.0
, por favor usa la respuesta de SolArabehety o mira este hilo.
Respuesta Original
package teste.blink; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.widget.TextView; public class TesteBlinkActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); blink(); } private void blink(){ final Handler handler = new Handler(); new Thread(new Runnable() { @Override public void run() { int timeToBlink = 1000; //in milissegunds try{Thread.sleep(timeToBlink);}catch (Exception e) {} handler.post(new Runnable() { @Override public void run() { TextView txt = (TextView) findViewById(R.id.usage); if(txt.getVisibility() == View.VISIBLE){ txt.setVisibility(View.INVISIBLE); }else{ txt.setVisibility(View.VISIBLE); } blink(); } }); } }).start(); }
<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"/>
Puede utilizar esto:
TextView myText = (TextView) findViewById(R.id.myText ); Animation anim = new AlphaAnimation(0.0f, 1.0f); anim.setDuration(50); //You can manage the blinking time with this parameter anim.setStartOffset(20); anim.setRepeatMode(Animation.REVERSE); anim.setRepeatCount(Animation.INFINITE); myText.startAnimation(anim);
Es la misma respuesta que he dado en este mensaje Texto intermitente en la vista de Android
¡Espero que esto ayude!
Utilice animaciones XML para este propósito:
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>
Actividad Blink: úsalo así: –
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) { } }
Déjame saber si tienes alguna pregunta ..
Cree una AlphaAnimation y aplíquela a la vista de texto en la actividad donde ha configurado la vista de texto. El parpadeo se lograría repitiendo una animación de 1,0 alfa a 0,0 alfa a 1,0 alfa.
Editar : Google provideth .
No es necesario establecer para esto. Sólo alfa:
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"/>
Y en código:
mTextView.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.flash_leave_now));
Usted puede hacer una animación o tal vez por qué no lo hace View.VISIBLE y View.INVISIBLE con un temporizador? Creo que la mejor manera es la animación con alpha de hecho 🙂
Aquí está mi implementación de ayuda con una animación alfa:
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); }