我正在制作一个动态文本视图的示例,它是通过按下按钮创建的。创建它们的格式类似于:
1- Textview (fist created)
2- TextView
3- TextView (last created)
我想知道我们是否可以按升序创建它们,在前一个 TextView 之上。像这样的东西:
3- TextView (last created)
2- TextView
1- TextView (first created)
这是我的示例代码:
private OnClickListener onClick() {
return new OnClickListener() {
@Override
public void onClick(View v) {
mLayout.addView(createNewTextView("TextView"));
count = count +1;
}
};
}
private TextView createNewTextView(String text) {
final LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
final TextView textView = new TextView(this);
textView.setLayoutParams(lparams);
textView.setText(count+ "- " + text);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
return textView;
}}