Line Button Margin

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?

+3
source share
2 answers

I really don't think they have a margin, but this is due to the background of the button. The default background of the button probably has an image like this:

http://developer.android.com/guide/developing/tools/draw9patch.html

. 9-.

http://developer.android.com/guide/topics/resources/drawable-resource.html

, "", , -3 (IHMO).

+11

Layout Params.. ... , , .

for (int = 0; < 3; ++)

{
    Button btn = new Button(activity);


    btn.setText("Button");


    mylayout.addView(pv);

}
0

Source: https://habr.com/ru/post/1786582/


All Articles