以编程方式设置 Imageview 宽度
我已经尝试了很多方法,但似乎对我不起作用。
我的代码: <代码> TableLayout tTopic=(TableLayout) findViewById(R.id.__topic);
TableRow tr = new TableRow(this);
TableLayout.LayoutParams lpt2=null;
lpt2 = new TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT);
lpt2.setMargins(4, 2, 4, 2);
tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
ImageView view = new ImageView(this);
view.setLayoutParams(new LayoutParams(20,30));
view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
view.setImageResource(R.drawable.kotak);
tr.addView(view);
tTopic.addView(tr,lpt2);
为什么根本不出现?但是当我省略 setLayoutParams 时,它会显示为默认大小。感谢您的帮助
I already try many ways but it seems doesn't work with me.
my code :
TableLayout tTopic=(TableLayout) findViewById(R.id.__topic);
TableRow tr = new TableRow(this);
TableLayout.LayoutParams lpt2=null;
lpt2 = new TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT);
lpt2.setMargins(4, 2, 4, 2);
tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
ImageView view = new ImageView(this);
view.setLayoutParams(new LayoutParams(20,30));
view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
view.setImageResource(R.drawable.kotak);
tr.addView(view);
tTopic.addView(tr,lpt2);
Why it doesn't appear at all? but when I omitted setLayoutParams it appear as default size. Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
要以编程方式设置 ImageView 宽度,请执行以下操作:
To set ImageView width programmatically do this: