Android ImageButton忽略将父映像与源映像对齐
我想让我的图像按钮保持它们的纵横比,所以我照做了 并将背景设置为空,然后将图像按钮源图像设置为图像按钮。现在的问题是图像按钮不再像以前那样与父对象对齐。如何使其再次与父右侧边缘对齐Android ImageButton忽略将父映像与源映像对齐,android,user-interface,Android,User Interface,我想让我的图像按钮保持它们的纵横比,所以我照做了 并将背景设置为空,然后将图像按钮源图像设置为图像按钮。现在的问题是图像按钮不再像以前那样与父对象对齐。如何使其再次与父右侧边缘对齐 ImageButton bt = new ImageButton(this); bt.setImageResource(R.drawable.next_button); bt.setBackgroundDrawable(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;
我最后只是硬编码了dp中按钮的尺寸。我搜索了一堆,除了这个,找不到任何有好的解决方案的人。它在哪里对齐?@jonfhanchock在中间,我还应该补充一点,我想按钮不是正方形的