¿Cómo crear un efecto de marquesina para un texto de menor longitud que no exceda el tamaño de la pantalla en Android?

He estado intentando dar el efecto de la marquesina para la palabra HOLA en mi uso pero el androide no permite el mismo a menos que la longitud del texto exceda el tamaño de la pantalla. ¿Hay una solución a su alrededor?

PS: Tan simple como esto parece que no tengo mis manos en cualquier solución todavía.

Utilicé el peso ligero simple del ticker como la animación que desarrollé en mis días androides tempranos.

Debajo es el código completo.

Espero que esto ayude.

Funciona para todos los niveles de API de Android

import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.view.Menu; import android.view.View; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setticker("Hello", this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void setticker(String text, Context contx) { if (text != "") { LinearLayout parent_layout = (LinearLayout) ((Activity) contx) .findViewById(R.id.ticker_area); TextView view = new TextView(contx); view.setText(text); view.setTextColor(Color.BLACK); view.setTextSize(25.0F); Context context = view.getContext(); // gets the context of the view // measures the unconstrained size of the view // before it is drawn in the layout view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); // takes the unconstrained width of the view float width = view.getMeasuredWidth(); float height = view.getMeasuredHeight(); // gets the screen width float screenWidth = ((Activity) context).getWindowManager() .getDefaultDisplay().getWidth(); view.setLayoutParams(new LinearLayout.LayoutParams((int) width, (int) height, 1f)); System.out.println("width and screenwidth are" + width + "/" + screenWidth + "///" + view.getMeasuredWidth()); // performs the calculation float toXDelta = width - (screenWidth - 0); // sets toXDelta to -300 if the text width is smaller that the // screen size if (toXDelta < 0) { toXDelta = 0 - screenWidth;// -300; } else { toXDelta = 0 - screenWidth - toXDelta;// -300 - toXDelta; } // Animation parameters Animation mAnimation = new TranslateAnimation(screenWidth, toXDelta, 0, 0); mAnimation.setDuration(15000); mAnimation.setRepeatMode(Animation.RESTART); mAnimation.setRepeatCount(Animation.INFINITE); view.setAnimation(mAnimation); parent_layout.addView(view); } } } 

En activity_main.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/ticker_area" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#9CB1DD" android:orientation="horizontal" > </LinearLayout> </RelativeLayout> 

Existe una solución simple

Deberá crear un marco WebView y mostrar como este código a continuación.

 webView = (WebView)findViewById(R.id.web); String summary = "<html><FONT color='#fdb728' FACE='courier'><marquee behavior='scroll' direction='left' scrollamount=10>" + "Hello Droid" + "</marquee></FONT></html>"; webView.loadData(summary, "text/html", "utf-8"); 

Intente usar Tickerview desde Git Hub.

Aquí está el código completo para su problema:

Main_Activity.java Código: '

  WebView webView; webView = (WebView)findViewById(R.id.web); String summary = "<html><FONT color='#fdb728' FACE='courier'><marquee behavior='scroll' direction='left' scrollamount=10>" + "Hello Droid" + "</marquee></FONT></html>"; webView.loadData(summary, "text/html", "utf-8"); // Set focus to the textview' 

Main_activity.xml código:

 <WebView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/web" ></WebView> 
  • Cómo cambiar el icono de un botón mediante programación?
  • Acceso a TextView desde otra clase
  • Visualización de varias líneas de texto y variables en un AlertDialog mediante setMessage ()
  • Cómo agregar una ruptura de línea en un Android TextView?
  • Android: No se puede cambiar el texto aparece en AlertDialog
  • Establecer TextView texto de html-formatted cadena recurso en XML
  • Cómo reemplazar elipses con fade / fading edge en textview en Android sdk?
  • ¿Hay una manera de crear el stackoverfow "Etiquetas" EditText / Campo de entrada en Android?
  • Android establece la gravedad de un TextView mediante programación
  • Cómo ajustar el kerning de texto en Android TextView?
  • ¿Hay una manera de agregar la sombra interna a un TextView en Android?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.