ビューのx、yの位置にImageButtonを配置したいと思います。問題は、Androidが画像の周りにパディングを追加することです。パディングの正確なサイズがわからないため、画像ボタンを正確な位置に配置できません。だから、私はパディングを削除したいと思います。プログラムで画像の周りのパディングを削除するにはどうすればよいですか?button.setPadding(0、0、0、0)は、ボタンの幅をビットマップより短くし、高さを長くします。button.getLayoutParams()。widthはマイナスの値を示します。今までやってみたのはこんな感じ。
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);
}
}