I want to place ImageButton at x, y location of my view. The problem is that Android adds padding around image. Because I don t know exact size of padding, I cannot place image button at exact location. So, I want to remove padding. How can I remove padding around image programmatically? button.setPadding(0, 0, 0, 0) makes button width shorter and height longer than bitmap. button.getLayoutParams().width gives minus value. What I tried so far is like this.
protected class MyLayout extends RelativeLayout {
Bitmap img;
ImageButton button;
public MyLayout(Context context) {
button = new ImageButton(context);
img = BitmapFactory.decodeResource(getResources(), R.drawable.img);
button.setImageBitmap(img);
params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
button.setLayoutParams(params);
params.setMargins(x, y, 0, 0);
button.setBackgroundDrawable(null);
addView(button, params);
}
}