2017-01-25 33 views
0

在xml文件裏面的相對佈局我已經採用了textview。我在java文件中提供了文本,字體大小,文本顏色。但仍然無法獲得選取框文字。我應該怎麼做。 在此先感謝如何動態製作字幕文本

MainActivity.java文件

public class MarqueeActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_marquee); 

     // got the data from another activity 
     String str = getIntent().getStringExtra("Text"); 
     float fontSize = getIntent().getFloatExtra("FontSize", 64.0f); 
     int textColor = Color.alpha(getIntent().getIntExtra("TextColor",0xff0000ff)); 
     int bgColor = Color.alpha(getIntent().getIntExtra("BGCOLOR",0xff0000ff)); 

     RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.activity_marquee); 
     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); 
     // created text view 
     TextView marqueeText = new TextView(this); 
     marqueeText.setText(str); 
     marqueeText.setTextSize(fontSize); 
     marqueeText.setTextColor(Color.alpha(textColor)); 
     marqueeText.setBackgroundColor(Color.alpha(bgColor)); 
     marqueeText.setTypeface(Typeface.MONOSPACE,Typeface.BOLD); 
     marqueeText.setSelected(true); 
     marqueeText.setSingleLine(true); 
     marqueeText.setMarqueeRepeatLimit(-1); 
     marqueeText.setHorizontallyScrolling(true); 

     relativeLayout.addView(marqueeText,params); 
    } 
} 

請更正上面的代碼來獲得滾動字幕文本

回答

0

您所需的人員爲你做,那是錯誤的。

您可以使用: 字符串在XML 陣列在XML

創建一個隨機函數,然後從列表中,陣列中的隨機元素等