I wanted my image buttons to maintain their aspect ratio so I followed https://stackoverflow.com/a/7966838/135135
and set the background to be null, and then set the image button source image to be the image button. The issue is now that the image button is not aligning with the parent as it was anymore. How do I make it align with the parent right edge again?
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;