【问题标题】:how to make marquee text dynamically如何动态制作选取框文本
【发布时间】:2017-01-25 18:03:34
【问题描述】:

在相对布局内的 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);
    }
}

请更正上述代码以获取字幕文本

【问题讨论】:

    标签: android flashlight


    【解决方案1】:

    你希望人们为你做这件事,那是错误的。

    您可以使用: XML 中的字符串 XML 中的数组

    创建一个随机函数,从列表、数组等中选择一个随机元素

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-22
      • 2012-04-14
      • 1970-01-01
      相关资源
      最近更新 更多