0
我希望我的圖像的按鈕,以保持它們的縱橫比對準父所以隨後https://stackoverflow.com/a/7966838/135135的ImageButton忽略與源圖像
,並設置背景爲空,然後將圖像按鈕源圖像爲圖像按鈕。現在的問題是,圖像按鈕不再像以前那樣與父對齊。我如何讓它再次與父母的右邊緣對齊?
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;
它在哪裏對齊? –
@jonfhancock中心,我還應該補充說,按鈕是不正方形我想 – RyanCheu