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 20x20 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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With