I place 36 buttons on a 6x6 matrix on the screen. between the buttons there is a gap-white stripes. How can someone get rid of them? size of pictures in files png 66x106

screen .

RelativeLayout rl= (RelativeLayout) findViewById(R.id.rl); for (i=.... { ... mButton[ind[i]] = new ImageButton(mContext); mButton[ind[i]].setImageResource(drawableId); mButton[ind[i]].setLayoutParams(new LinearLayout.LayoutParams(wb, hb)); mButton[ind[i]].setId(drawableId); mButton[ind[i]].setX(x); mButton[ind[i]].setY(y); rl.addView(mButton[ind[i]]); x += wb; // wb=66 y += hb; // hb=106 ...... } 

layout.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:id="@+id/rl" tools:context=".GameActivity" android:orientation="vertical"> </RelativeLayout> 

    2 answers 2

    These lines set the padding:

      android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" 

    Try setting the desired values ​​there, for example, "1dp" (or "0dp", if not at all).

    UPD. Try this:

     button.setBorder(null); button.setBorderPainted(false); button.setMargin(new Insets(0,0,0,0)); 

    You can also register in the XML buttons android:padding="0dp"

    • These indents are from the edges of the screen, not between pictures - pavlofff
    • mButton [ind [i]]. setLayoutParams (new LinearLayout.LayoutParams (wb, hb)); can add something similar to this "android: padding ..." to this markup? - Serg Sergeev
    • Yes, the same indents for pictures to register. - Pavel Krizhanovskiy
    • how exactly? (applied to my code). Thank you. - Serg Sergeev
    • Added in response. - Pavel Krizhanovskiy

    The problem may be in the ImageButton class ImageButton , namely in its margin/padding , which can be set by default. IMHO he is not needed at all.
    Try replacing it with a regular image: ImageView