I create several buttons and add them to the linear layout, which is defined as
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/mylayout">
</LinearLayout>
Buttons are created using
for (int i = 0; i < 3; i++)
{
Button btn = new Button(activity);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(1, 1, 1, 1);
btn.setText("Button");
btn.setPadding(0, 0, 0, 0);
mylayout.addView(pv, lp);
}
These buttons always have a margin (about 3 pixels) that I would like to remove. Is there something I can't see? If I use the custom view I created, there is no space between them.
Should I Install
lp.setMargins (-3, -3, -3, -3);
which removes margin? Is there a flaw in this?
source
share