Android:如何创建由EditText组成的视图?
我正在创建编辑文本:Android:如何创建由EditText组成的视图?,android,Android,我正在创建编辑文本: EditText et=new EditText(this); et.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 还有一个观点: View myView = new View(this); 我希望(仅)此视图中的EditText。 我该怎么做呢?在Android活动上放置视图(或“UI元素”)的常用方法是创建它们(以代码或X
EditText et=new EditText(this);
et.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
还有一个观点:
View myView = new View(this);
我希望(仅)此视图中的EditText。
我该怎么做呢?在Android活动上放置
视图(或“UI元素”)的常用方法是创建它们(以代码或XML格式),然后将它们放置在一个显示的视图中
由于您只需要一个视图
,因此可以使用:
FrameLayout设计用于在屏幕上标出要显示的区域
单一项目
示例代码和更多信息可以在链接文档中找到。我认为,您需要在活动中只显示编辑文本。为此,您可以执行以下操作:
LinearLayout l=new LinearLayout(context);
EditText et=new EditText(this);
et.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
l.addView(et);
setContentView(l);
不要多次问同一个问题详细说明这个问题。@Hades-不是同一个问题。现在我可以创建EditText,但我想创建一个视图,其中EditText已经是一个视图了,为什么要将它放在另一个视图中?@Belgi,一个视图不能包含另一个视图。只有ViewGroups
可以包含其他视图。使用xxxLayout
进行任何尝试。