简体   繁体   中英

How to remove padding between grid of ImageButtons

I have the next XML with 4 Imagebuttons , I've set the images in two LinearLayouts and i gave the buttons weight of 1 so they will be oredered in the same line ,

 <LinearLayout
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_width="match_parent">
        <ImageButton
            android:id="@+id/bt5"
            android:layout_width="match_parent"
            android:layout_height="90dp"
            android:layout_weight="1"
            android:onClick="btClick"
            android:scaleType="fitXY"
            android:tag="empty" />
        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="90dp"
            android:onClick="btClick"
            android:scaleType="fitXY"
            android:id="@+id/bt6"
            android:layout_weight="1"
            android:tag="empty"
            />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageButton
            android:layout_marginRight="0dp"
            android:layout_marginTop="0dp"
            android:layout_width="match_parent"
            android:layout_height="90dp"
            android:onClick="btClick"
            android:id="@+id/bt7"
            android:layout_weight="1"
            android:scaleType="fitXY"
            android:tag="empty"
            />

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="90dp"
            android:onClick="btClick"
            android:id="@+id/bt8"
            android:layout_weight="1"
            android:scaleType="fitXY"
            android:tag="empty"
            />
    </LinearLayout>

And as you can there are empty space between the buttons , is there a way to remove that space and make the stick to each other? 在此处输入图片说明

Try this :- ( using android:layout_marginLeft="-3dp" or android:layout_marginRight="-3dp"

<ImageButton
        android:id="@+id/bt5"
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:layout_weight="1"
        android:onClick="btClick"
        android:scaleType="fitXY"
        android:tag="empty"
        android:layout_marginRight="-3dp" />
    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:onClick="btClick"
        android:scaleType="fitXY"
        android:id="@+id/bt6"
        android:layout_weight="1"
        android:tag="empty"
        android:layout_marginLeft="-3dp"
        />

You can use remove that by adding either:

android:background="@null "

or:

android:background="@android:color/transparent"

or:

style="?android:attr/borderlessButtonStyle"

to the ImageButton .

But you will not be able to identify the buttons. You should add different background colors or borders to separate them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM