布局参数未显示
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayout);
for(int k=0;k<10;k++)
{ TableRow tr=new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
tr.setId(k);
for(int s=0;s<10;s++)
{
EditText edt=new EditText(this);
Log.i("SS","setting layout params for textview "+s+k);
edt.setText("abc "+s+k+" ");
edt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
ViewGroup.LayoutParams p=edt.getLayoutParams();
Log.i("SS","edt params "+p.height +" "+p.width);
tr.addView(edt);
}
ll.addView(tr);
}
}
在上面的代码
中,如果我删除行 edt.setLayoutParams... 将显示编辑文本。 但如果我设置了它们的参数,它们就不会显示。 知道可能是什么原因吗?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayout);
for(int k=0;k<10;k++)
{ TableRow tr=new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
tr.setId(k);
for(int s=0;s<10;s++)
{
EditText edt=new EditText(this);
Log.i("SS","setting layout params for textview "+s+k);
edt.setText("abc "+s+k+" ");
edt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
ViewGroup.LayoutParams p=edt.getLayoutParams();
Log.i("SS","edt params "+p.height +" "+p.width);
tr.addView(edt);
}
ll.addView(tr);
}
}
}
In the above code if i remove the line edt.setLayoutParams... the edit Texts are showing.
But if i set the their params they are not showing.
Any idea what could be the reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个...
希望这会帮助你...
Try out This...
Hope this will help u out...