android – Textview选框以编程方式
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android – Textview选框以编程方式,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2471字,纯文字阅读大概需要4分钟。
内容图文
尝试从数组中填充textview.我通过下面的代码设法通过XML获得了预期的效果
<?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>
但我需要在数组中使用其中的几个 – 所以我认为以编程方式创建文本视图可能是答案,但是无法将它们添加到字幕中.这是我正在努力的代码.
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);
}
解决方法:
试试这个.
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);
另外一个选项:
TextView textView = (TextView) this.findViewById(R.id.xxx);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setText("Text text text text");
textView.setSelected(true);
textView.setSingleLine(true);
内容总结
以上是互联网集市为您收集整理的android – Textview选框以编程方式全部内容,希望文章能够帮你解决android – Textview选框以编程方式所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。