[英]ImageView Width And Height Programmatically In TableLayout
Actullay all I want is in question title. Actullay我想要的只是问题标题。 I want to set fix width and height for ImageView in TableLayout.
我想在TableLayout中为ImageView设置修复宽度和高度。 How can I do it?
我该怎么做?
This is my code: 这是我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.buddy_list);
TableLayout buddy_list_layout = (TableLayout)findViewById(R.id.buddy_list_layout);
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.troll_logo);
//imageView.setLayoutParams(new TableLayout.LayoutParams(100, 100));
tableRow.addView(imageView);
buddy_list_layout.addView(tableRow);
} // end -> method -> onCreate
try as: 试着:
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams vp =
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(vp);
imageView.getLayoutParams().height = 20;
imageView.getLayoutParams().width = 20;
imageView.setImageResource(R.drawable.troll_logo);
////.......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.