0

I have some problems trying to add a background image in my button programmatically. It works well on my XML file, but programmatically the background image of my button is bigger than normal. I mean my image is High:150px but when I run this code its looks bigger. I had already try setting my button maxheight function, but it doesn't works. BTW the button is inside a row, and the row (obviously) inside a TableLayout.

Thanks in advice for the help!

for(int i = 0; i < 3; i++){
    TableRow tableRow = new TableRow(this);         
    tableRow.setId(0 + i);
    tableRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 150));   

    Button btnProduct = new Button (this);
    btnProduct.setId(10 + i);
    btnProduct.setBackgroundResource(R.drawable.shoes1);
    btnProduct.setHeight(150);
    btnProduct.setWidth(161);   
    btnProduct.setText("View");

    tableRow.addView(btnProduct);
    mainTableLayout.addView(tableRow);
}
4

1 回答 1

0

我同意 kabuko 的观点,您可能会将 dp(密度像素)与 px(普通像素)混淆,这种混淆可能会根据您的屏幕分辨率产生显着的尺寸差异。

于 2012-01-01T15:04:31.720 回答