如何在同一个线性布局中动态复制文本视图? [英] how to duplicate textview in the same linearlayout dynamically?
问题描述
我的问题似乎是这样的.我创建了一个布局文件,其中包含线性布局和文本视图.需要动态地(以编程方式)在同一线性布局中生成具有不同文本的文本视图的重复文本视图.任何人都可以提出正确的答案.
My question seems same like this. I've created a layout file with linearlayout and a textview inside it.Need to generate duplicate textviews of a textview with different texts in the same linearlayout dynamically(programmatically). Can anyone suggest the correct answer.
推荐答案
您可以在代码中动态创建一个 TextView
并将其添加到某个容器视图中.另一种方法可能是对 TextView 使用布局并执行以下操作(如果单个元素变得更复杂并且更易于使用布局来填充 TextView 的各种属性,则可以更好地扩展)
You can dynamically create a TextView
in code and add it to some container view. Another approach might be to use layout for TextView and do something like following (this scales better if individual elements get more complex and also easier to use layout to populate various attributes of TextView)
for (some loop) {
TextView textView = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.text_view_layout, null);
containerView.addView(textView);
}
containerView
将是您使用 findViewById
这篇关于如何在同一个线性布局中动态复制文本视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!