0

私が欲しいのは質問のタイトルだけです。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

次のように試してください:

    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 に答える