尝试从数组中填充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选框以编程方式所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)