Texto intermitente en la vista android
¿Cómo puedo mostrar texto intermitente en android.
Gracias a todos.
- Paginación de texto en Android
- Eliminar Negrita de la vista de texto sin cambiar otros atributos
- Cómo alinear un elemento a la derecha de su centro de padres? (Diseños de Android)
- .length () vs .getText (). Length () vs .getText (). ToString (). Length ()
- Limitar el número de líneas en TextView
- Android: escala la imagen de fondo de TextView para ajustar XY
- Establecer el color de enfoque de la vista de texto mediante programación / cambiar el color de enfoque en los temas
- Dos estilos diferentes en un solo textview con diversa gravedad y hieght
- Cómo encontrar texto visible en la vista de texto
- 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?
- Aumentar ListFragment inbuilt tamaño de la vista de texto vacío
- Configuración de textview en la parte inferior de android
- cómo establecerImage en el lado derecho Textview Programatically
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 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!
¡En realidad hay una etiqueta de pestaña de huevo de Pascua para esto en ICS! 🙂 Realmente no lo recomiendo usarlo – fue divertido REALMENTE para encontrarlo en la fuente, aunque!
<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>
Cree una animación de vista para ella. Usted puede hacer un fade alfa de 100% a 0% en 0 segundos y volver otra vez en un ciclo. De esta forma, Android maneja con inteligencia y no tienes que desordenar con el enhebrado y CPU de residuos.
Más información sobre animaciones aquí:
http://developer.android.com/reference/android/view/animation/package-summary.html
Se puede hacer mediante la adición de un ViewFlipper que alterna dos TextViews y Fadein y Fadeout animación se puede aplicar cuando cambian.
Archivo de diseño:
<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>
Código de 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));
El uso de subprocesos en el código siempre reduce el tiempo de CPU y disminuye el rendimiento de la aplicación. No debe usar hilos todo el tiempo. Utilícelo si es necesario.
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(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) { } }
Déjame saber si tienes alguna pregunta ..
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 crea el 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 crea el método de actualización para 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 funciona bien