LinearLayout.LayoutParams labellayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams textlayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
for(int i=0 ;i < 2;i++){
TextView label = new TextView(this);
EditText text = new EditText(this);
labellayoutParams.setMargins(40, 30, 30 , 0);
textlayoutParams.setMargins(60, 30, 30 , 0);
text.setHint("Type Here");
label.setText("some text");
ll.addView(label);
ll.addView(text);
}
this.setContentView(ll);
上面的代码将显示输出为
注意:让我们假设 sometext 作为 textview 和_ __ _作为 edittext
some text ____________ some text _____________
但我想要这样的输出
some text ____________
some text ____________
我试过 setOrientation(LinearLayout.VERTICAL) 但它给了喜欢这个
some text
_____________
some text
_____________