user1483756
user1483756

Reputation:

ImageView Width And Height Programmatically In TableLayout

Actullay all I want is in question title. I want to set fix width and height for ImageView in TableLayout. 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

Upvotes: 0

Views: 3526

Answers (1)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132992

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);
////.......

Upvotes: 2

Related Questions