画像ボタンのアスペクト比を維持したかったので、https://stackoverflow.com/a/7966838/135135をフォローしました
背景をnullに設定してから、画像ボタンのソース画像を画像ボタンに設定します。問題は、画像ボタンが親と整列していないことです。親の右端に再び揃えるにはどうすればよいですか?
ImageButton bt = new ImageButton(this);
bt.setImageResource(R.drawable.next_button);
bt.setBackgroundDrawable(null);
bt.setAdjustViewBounds(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
bt.setLayoutParams(params);
return bt;