0

Actullay 我想要的只是有问题的标题。我想在 TableLayout 中为 ImageView 设置固定宽度和高度。我该怎么做?

这是我的代码:

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
4

1 回答 1

2

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);
////.......
于 2012-07-03T20:10:00.903 回答