Respuesta
Crea una animación de la vista para él. Puede hacer un fundido alfa del 100% al 0% en 0 segundos y viceversa en un ciclo. De esta forma, Android lo maneja de forma inteligente y no tiene que preocuparse por el uso de la CPU.
Más sobre animaciones aquí:
http://developer.android.com/reference/android/view/animation/package-summary.html
¿Cuál es la mejor manera de mantener el texto parpadeando? –
En realidad no es una etiqueta de abrir y cerrar de huevos de Pascua para esto en ICS! :) En realidad, no recomiendo usarlo, ¡aunque me divirtió mucho encontrarlo en la fuente!
<blink xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I'm blinking"
/>
</blink>
No funcionó para mí: 'E/AndroidRuntime (19645): Causado por: android.view.InflateException: archivo XML binario línea n. ° 9: error al inflar la clase blink ' –
No está documentado, lo encontré por ICS de buceo en la fuente. Parece que el cambio se introdujo el 17-5-2011. No estoy seguro de qué número de SDK también se mapea. –
Ah, y si esto no fuera obvio, estoy bastante seguro de que la etiqueta "parpadear" es un huevo de Pascua. ¡No estoy sugiriendo seriamente que sea la solución correcta! :) –
Se puede hacer mediante la adición de un ViewFlipper que alterna dos TextViews y animación fadeIn y Fadeout se puede aplicar cuando cambian.
Archivo de diseño: Código
<ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="wrap_content" android:flipInterval="1000" >
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="TEXT THAT WILL BLINK"/>
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="" />
</ViewFlipper>
Actividad:
private ViewFlipper mFlipper;
mFlipper = ((ViewFlipper)findViewById(R.id.flipper));
mFlipper.startFlipping();
mFlipper.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out));
Se puede utilizar esta:
TextView myText = (TextView) findViewById(R.id.myText);
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50); //You can manage the time of the blink with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
myText.startAnimation(anim);
Espero que esto ayude!
realmente simple y realmente útil –
Copiar y pegar y ¡Bingo! ¡Gracias por compartir esto! –
Usar subprocesos en el código siempre desperdicia tiempo de CPU y disminuye el rendimiento de la aplicación. No deberías usar hilos todo el tiempo. Úselo si fuera necesario.
Uso 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 de parpadeo: utilizar de esta manera: -
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(getApplicationContext(),
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 saber si tiene alguna pregunta ..
cómo puedo hacer que parpadee con 3 colores gracias de antemano! –
@ We'reAllMadHere Le sugiero que use Value Animator para esta tarea, es muy fácil de usar. http://stackoverflow.com/questions/15582434/using-a-valueanimator-to-make-a-textview-blink-different-colors –
Esta es una manera muy clara de hacerlo, pero anima el todo TextView, incluido su color de fondo si no es transparente. ¿Hay alguna manera de parpadear solo el 'text' dentro de' TextView' –
If you want to make text blink on canvas in bitmap image so you can use this code
we have to create two methods
So first, let's declare a blink duration and a holder for our last update time:
private static final int BLINK_DURATION = 350; // 350 ms
private long lastUpdateTime = 0; private long blinkStart=0;
ahora crear método
public void render(Canvas canvas) {
Paint paint = new Paint();
paint.setTextSize(40);
paint.setColor(Color.RED);
canvas.drawBitmap(back, width/2 - back.getWidth()/2, height/2
- back.getHeight()/2, null);
if (blink)
canvas.drawText(blinkText, width/2, height/2, paint);
}
Ahora cree método de actualización a parpadear
public void update() {
if (System.currentTimeMillis() - lastUpdateTime >= BLINK_DURATION
&& !blink) {
blink = true;
blinkStart = System.currentTimeMillis();
}
if (System.currentTimeMillis() - blinkStart >= 150 && blink) {
blink = false;
lastUpdateTime = System.currentTimeMillis();
}
}
Ahora que funcionan bien
- 1. Android: Vista de Texto hipervínculo
- 2. una vista de texto en Android
- 3. Vista de desplazamiento para vista de texto en android
- 4. cómo ocultar el cursor parpadeante en el texto de entrada?
- 5. Android ¿Agregar imagen a texto (en vista de texto)?
- 6. Seguimiento del texto seleccionado en la vista web de Android
- 7. Permitir multilínea en la vista Editar texto en Android?
- 8. ¿Cómo "truncar" un texto dentro de la vista de texto en Android según la orientación?
- 9. ¿Cómo ocultar el cursor parpadeante del cuadro de texto?
- 10. android agregar '...' al final de la vista de texto
- 11. Uso de varios colores de texto en la vista de texto de Android [Html.fromhtml()]
- 12. Icono de bandeja parpadeante
- 13. Botón parpadeante en la aplicación WPF
- 14. El texto en la vista de texto se desliza hacia abajo en Android 3.0
- 15. Título parpadeante de Jquery
- 16. Cómo hacer zoom en una vista de texto en android?
- 17. ¿Cómo ajustar el texto a la siguiente línea en una vista de texto de Android?
- 18. Hacer una vista de texto de hipervínculo en android
- 19. arrastrar y soltar vista de texto en android
- 20. Cuenta atrás con la vista de texto
- 21. Mostrar texto dinámico en una vista de Android
- 22. haciendo una vista de texto hacer clic en Android
- 23. ¿Por qué el cursor parpadeante en el campo de texto hace que se llame a drawRect?
- 24. Mostrando el cursor parpadeante en la entrada de texto no enfocado
- 25. Deshabilitar el cursor parpadeante de EditText
- 26. Parpadeante jQuery .animation()
- 27. jQuery "efecto de resaltado parpadeante" en div?
- 28. Android aplicar el estilo de Vista de Texto de encargo
- 29. Cómo eliminar la sangría del primer carácter en la vista de texto de Android
- 30. android - alinear una vista de texto en el centro de otra vista
Ha intentado cambiar el color del texto cada segundo, por ejemplo? porque no creo que puedas hacer eso con el marco. o tal vez puede usar una vista web con una etiqueta parpadeante ... – Sephy
puede crear un hilo que alterne la visibilidad de textView entre View.VISIBLE y View.INVISIBLE –
En realidad, no creo que puedas hacer una WebView como sugirió Sephy; Webkit no representa la etiqueta