2012-09-15 79 views
2
TextView txt = new TextView(this); 
    txt.setText(「This is moving text」); 
    txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); 
    txt.setTextColor(Color.rgb(187, 88, 15)); 
    txt.setPadding(10, 10, 0, 0); 
    txt.setEllipsize(TruncateAt.MARQUEE); 
    txt.setSingleLine(); 
    txt.setMarqueeRepeatLimit(10); 
    txt.setFocusable(true); 
    txt.setHorizontallyScrolling(true); 
    txt.setFocusableInTouchMode(true); 
    txt.requestFocus(); 
    txt.setTypeface(Typeface.SERIF,Typeface.BOLD); 

我試圖爲textview創建移動文本,但它不會移動。我嘗試使用setMarqueeRepeatLimit。怎麼做?在文本視圖中移動文本

+0

http://stackoverflow.com/questions/3332924/textview-marquee-not-working這會幫助你 –

+0

請參閱[本教程]( http://androidbears.stellarpc.net/?p=185)適合你的場景 –

回答

3

的答案是:

TextView txt = new TextView(this);  
txt.setText(「This is moving text」);  
txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);  
txt.setTextColor(Color.rgb(187, 88, 15));  
txt.setPadding(10, 10, 0, 0);  
txt.setEllipsize(TruncateAt.MARQUEE);  
txt.setSingleLine();  
txt.setMarqueeRepeatLimit(10);  
txt.setFocusable(true);  
txt.setHorizontallyScrolling(true);  
txt.setFocusableInTouchMode(true);  
txt.requestFocus();  
txt.setLayoutParams(new TableRow.LayoutParams(130, TableRow.LayoutParams.FILL_PARENT)); 
txt.setTypeface(Typeface.SERIF,Typeface.BOLD);