So, why does this code:
package org.popoffka.apicross;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class Game extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button testButton = new Button(this);
testButton.setBackgroundResource(R.drawable.cell);
testButton.setWidth(20);
testButton.setHeight(20);
setContentView(testButton);
}
}
…produce this thing:
http://i42.tinypic.com/2hgdzme.png even though there’s a setWidth(20) and setHeight(20) in the code?
(R.drawable.cell is actually a 20×20 PNG image containing a white cell with a silver border)
The proper way to set the width and height of a View is to do so via the LayoutParams. See ViewGroup.LayoutParams and View.getLayoutParams().