如何动态添加 TextView 到此?注释掉的代码不起作用。
public class myTextSwitcher extends Activity {
private TextView myText;
public myTextSwitcher(String string){
//myText = new TextView(this);
//myText.setText("My Text");
}
}
您正在创建一个文本视图并设置其值,但没有指定它的显示位置和显示方式。您的 myText 对象需要有某种使其可见的容器。
您想要做的是动态布局视图。请参阅此处很好的入门文章 http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/。来自文章:
// This is where and how the view is used
TextView tv = new TextView(this);
tv.setText("Dynamic layouts ftw!");
ll.addView(tv);
// this part is where the containers get "wired" together
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)