Reputation: 127
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):
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?
Upvotes: 0
Views: 2009
Reputation: 949
By default it has a background with a margin.
In code:
ImageButton imageButton = ImageButton.class.cast(rootView.findViewById(R.id.imageButton));
imageButton.setBackground(null);
In xml file:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:background="@null" />
"rootView" is the layout inflated to fragment or activity.
Upvotes: 0
Reputation: 2810
Set your image button background is null. eg.
ib.setBackground(null);
Upvotes: 4