2017-01-29 2 views
3

Versuchen, eine Textansicht (en) aus einem Array zu füllen. Ich schaffte es die gewünschte Wirkung per XML über den Code untenTextview-Laufschrift programmgesteuert

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/marque_scrolling_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:padding="16dp" 
     android:scrollHorizontally="true" 
     android:singleLine="true" 
     android:text="Create a Marquee (Scrolling Text) in Android Using TextView. Android Marquee (Scrolling Text) Tutorial with Example" 
     android:textSize="24sp" /> 
</LinearLayout> 

zu bekommen, aber ich brauche mehrere davon in einem Array - so glaube ich, die Textviews Erstellen die Antwort kann programmatisch sein, aber kann nicht bekommen, sich Zelt. Dies ist der Code, an dem ich arbeite.

String[] strings = {"Mark", "James", "Paul"}; 
     LinearLayout layout = (LinearLayout)findViewById(R.id.linearlayout); 


     for(String s : strings) 
     { 
      TextView newTextView = new TextView(this); 
      newTextView.setText(s); 
      newTextView.setSingleLine(true); 
      newTextView.setEllipsize(TextUtils.TruncateAt.END);  
      newTextView.setHorizontallyScrolling(true); 
      newTextView.setLines(1); 
      newTextView.setMarqueeRepeatLimit(-1); 
      newTextView.setSelected(true); 
      newTextView.setTextSize(24); 
      layout.addView(newTextView); 
     } 

Antwort

2

Versuchen Sie es.

final RelativeLayout relativeLayout = new RelativeLayout(this); 
final RelativeLayout relativeLayoutbotombar = new RelativeLayout(this); 
textView = new TextView(this); 
textView.setId(1); 

RelativeLayout.LayoutParams relativlayparamter = new RelativeLayout.LayoutParams(
        RelativeLayout.LayoutParams.MATCH_PARENT, 
        RelativeLayout.LayoutParams.MATCH_PARENT); 

     RelativeLayout.LayoutParams relativlaybottombar = new RelativeLayout.LayoutParams(
       RelativeLayout.LayoutParams.WRAP_CONTENT, 
       RelativeLayout.LayoutParams.WRAP_CONTENT); 
     relativeLayoutbotombar.setLayoutParams(relativlaybottombar); 


     textView.setText("text text text text text, with a long "); 
     textView.setEllipsize(TruncateAt.MARQUEE); 
     textView.setSelected(true); 
     textView.setSingleLine(true); 


     relativeLayout.addView(relativeLayoutbotombar); 
     relativeLayoutbotombar.addView(textView); 
     setContentView(relativeLayout, relativlayparamter); 

Eine weitere Option:

TextView textView = (TextView) this.findViewById(R.id.xxx); 
textView.setEllipsize(TruncateAt.MARQUEE); 
textView.setText("Text text text text"); 
textView.setSelected(true); 
textView.setSingleLine(true); 
+0

Danke für die prompte Antwort, aber nicht zu funktionieren scheint - kein Scrollen. –

+0

Überprüfen Sie das Update @MarkJames – josedlujan

4

die Sie interessieren .. Es funktioniert

TextView testing = (TextView) this.findViewById(R.id.testing); 
testing.setEllipsize(TextUtils.TruncateAt.MARQUEE); 
testing.setMarqueeRepeatLimit(-1); 
testing.setSingleLine(true); 
testing.setSelected(true);