versiones pie oreo developer descargar android

oreo - android pie



Texto de marquesina en Android (15)

Encontré un problema con marquesina que no se puede usar para cadenas cortas (ya que su función es solo mostrar cuerdas largas).

Sugiero Usar Webview si quieres mover cadenas cortas horizontalmente. Código Main_Activity.java: `

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 `

código main_activity.xml:

<WebView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/web" ></WebView>

¿Cómo puedo usar el texto de marquesina en una aplicación de Android?


Además de las configuraciones XML identificadas por droidgren, mis pruebas han demostrado que si el texto que desea mostrar es más corto que el ancho de la vista de texto, entonces la marquesina no se desplazará en absoluto. Las soluciones posibles son establecer el ancho de la vista a un tamaño menor que la longitud del texto, o concatenar la cadena a sí mismo 2 o 3 veces, con espacios en blanco entre los adecuados para que el desplazamiento se vea bien.


Agregue el código siguiente en XML

<TextView android:text="Shops NearBy textdf fsdgsdgsdg dsgtsgsdgsdgsg" android:id="@+id/txtEventName" android:ellipsize="marquee" android:marqueeRepeatLimit ="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" android:scrollHorizontally="true" android:singleLine="true"/>

En Java, agregue el siguiente código:

TextView txtEventName=(TextView)findViewById(R.id.txtEventName); txtEventName.setSelected(true);


Aquí hay un ejemplo:

public class TextViewMarquee extends Activity { private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv = (TextView) this.findViewById(R.id.mywidget); tv.setSelected(true); // Set focus to the textview } }

El archivo xml con la vista de texto:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/mywidget" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:maxLines="1" android:ellipsize="marquee" android:fadingEdge="horizontal" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:textColor="#ff4500" android:text="Simple application that shows how to use marquee, with a long text" /> </RelativeLayout>


Código Xml

<TextView android:id="@+id/txtTicker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_gravity="center_horizontal" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:freezesText="true" android:gravity="center_horizontal" android:marqueeRepeatLimit="marquee_forever" android:paddingLeft="5dip" android:paddingRight="5dip" android:scrollHorizontally="true" android:shadowColor="#FF0000" android:shadowDx="1.5" android:shadowDy="1.3" android:shadowRadius="1.6" android:singleLine="true" android:textColor="@android:color/white" android:textSize="20sp" android:textStyle="bold" > </TextView>

Java

txtEventName.setSelected(true);

si el texto es pequeño, añada espacio antes y después del texto

txtEventName.setText("/t /t /t /t /t /t"+eventName+"/t /t /t /t /t /t");


Con la respuesta anterior, no puede establecer la velocidad ni tener flexibilidad para personalizar la funcionalidad de vista de texto. Para tener su propia velocidad de desplazamiento y flexibilidad para personalizar las propiedades de marquesina, use lo siguiente:

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:fadingEdge="horizontal" android:lines="1" android:id="@+id/myTextView" android:padding="4dp" android:scrollHorizontally="true" android:singleLine="true" android:text="Simple application that shows how to use marquee, with a long text" />

Dentro de tu actividad:

private void setTranslation() { TranslateAnimation tanim = new TranslateAnimation( TranslateAnimation.ABSOLUTE, 1.0f * screenWidth, TranslateAnimation.ABSOLUTE, -1.0f * screenWidth, TranslateAnimation.ABSOLUTE, 0.0f, TranslateAnimation.ABSOLUTE, 0.0f); tanim.setDuration(1000);//set the duration tanim.setInterpolator(new LinearInterpolator()); tanim.setRepeatCount(Animation.INFINITE); tanim.setRepeatMode(Animation.ABSOLUTE); textView.startAnimation(tanim); }


En el archivo XML, debe agregar los siguientes atributos adicionales en un TextView para obtener una característica similar a una marquesina:

android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true"

En el archivo MainActivity.java, puede obtener la referencia de este TextView utilizando findViewById () y puede establecer la siguiente propiedad en este TextView para que parezca un texto de marquesina:

setSelected(true);

Eso es todo lo que necesitas.


Esto será equivalente a "final":

where = TruncateAt.END


He intentado todo lo anterior, pero para mí no funcionó. Cuando agrego

android:clickable="true"

entonces funcionó perfectamente para mí. No sé por qué. Pero estoy feliz de trabajarlo.

Aquí está mi respuesta completa.

android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:clickable="true"


Para que esto funcione, tuve que usar TODAS las tres cosas (ellipsize, selected, y singleLine) mencionadas anteriormente:

TextView tv = (TextView)findViewById(R.id.someTextView); tv.setSelected(true); tv.setEllipsize(TruncateAt.MARQUEE); tv.setSingleLine(true):


Puede usar un TextView o su TextView personalizado. Lo último es cuando la vista de texto no puede enfocarse todo el tiempo.

En primer lugar, puede usar una vista de texto o una vista de texto personalizada como la vista de texto desplazable en su archivo de distribución .xml de la siguiente manera:

<com.example.myapplication.CustomTextView android:id="@+id/tvScrollingMessage" android:text="@string/scrolling_message_main_wish_list" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit ="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" android:scrollHorizontally="true" android:layout_width="match_parent" android:layout_height="40dp" android:background="@color/black" android:gravity="center" android:textColor="@color/white" android:textSize="15dp" android:freezesText="true"/>

NOTA: en el fragmento de código anterior, com.example.myapplication es un nombre de paquete de ejemplo y debe ser reemplazado por su propio nombre de paquete.

Luego, en caso de utilizar CustomTextView, debe definir la clase CustomTextView:

public class CustomTextView extends TextView { public CustomTextView(Context context) { super(context); } public CustomTextView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if(focused) super.onFocusChanged(focused, direction, previouslyFocusedRect); } @Override public void onWindowFocusChanged(boolean focused) { if(focused) super.onWindowFocusChanged(focused); } @Override public boolean isFocused() { return true; } }

Espero que sea útil para ti. ¡Aclamaciones!


Simplemente ponga estos parámetros en su TextView - Funciona: D

android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:focusable="true" android:focusableInTouchMode="true"

Y también necesita establecer setSelected(true) :

my_TextView.setSelected(true);

Saludos, Christopher


Use esto para configurar Marque:

final TextView tx = (TextView) findViewById(R.id.textView1); tx.setEllipsize(TruncateAt.MARQUEE); tx.setSelected(true); tx.setSingleLine(true); tx.setText("Marquee needs only three things to make it run and these three things are mentioned above.");

No necesita usar " android: marqueeRepeatLimit =" marquee_forever "en el archivo xml. Marquee funcionará incluso sin esto.


TextView textView = (TextView) this.findViewById(R.id.textview_marquee); textView.setEllipsize(TruncateAt.MARQUEE); textView.setText("General Information... general information... General Information"); textView.setSelected(true); textView.setSingleLine(true);


android:ellipsize="marquee"

Esto solo funciona cuando su TextView tiene el foco.