Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ImageButton忽略将父映像与源映像对齐_Android_User Interface - Fatal编程技术网

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在中间,我还应该补充一点,我想按钮不是正方形的