Search code examples
androidandroid-layoutandroid-imagebutton

Android : Image button has unwanted margin


I have some image buttons in my android project. but they have some gray margins like this pic(I take this pic from real device):

enter image description here

How can I remove them?? I used this code but it doesn't have any effect.

 ib.setAdjustViewBounds(true);     

Image buttons just defined in java and I don't have them on xml.

 ib = new ImageButton(this);
 ib.setImageResource(R.drawable.image);
 ib.setAdjustViewBounds(true);
 ib.setLayoutParams(ibrllp);

How can I remove this additional gray margin?


Solution

  • Set your image button background is null. eg.

    ib.setBackground(null);