Search code examples
androidxmlandroid-relativelayout

Android Image Button not wrapping correctly?


I set Image Button to wrap content an its layout to do the same, but the buttons still showing something like a padding on the top and the bottom.

I already tried setting padding and margin to 0dp, didn't worked.

Image of the layout (Please, ignore the two Image Buttons without image source)

Code:

<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="arensis.grumpyworld.game">
//This is not the image
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fondo"
        android:scaleType="fitCenter"
        android:src="@drawable/fondo1"
        android:layout_above="@+id/linearLayout2"
        android:layout_centerHorizontal="true" />
//Neither this one.
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/gato"
        android:scaleType="fitCenter"
        android:src="@drawable/grumpymodel"
        android:layout_above="@+id/linearLayout2"
        android:layout_centerHorizontal="true" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="3"
        android:layout_gravity="center_vertical"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="0dp"
        android:id="@+id/linearLayout">

        <ImageButton
            android:scaleType="fitCenter"
            android:id="@+id/mapaico"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="0dp" />

        <ImageButton
            android:scaleType="fitCenter"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:id="@+id/cazaico"
            android:src="@drawable/cazaico" />

        <ImageButton
            android:scaleType="fitCenter"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:id="@+id/dueloico"
            />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="3"
        android:layout_above="@+id/linearLayout"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="0dp"
        android:id="@+id/linearLayout2">

        <ImageButton
            android:scaleType="fitCenter"
            android:id="@+id/gcico"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:src="@drawable/gcico" />

        <ImageButton
            android:scaleType="fitCenter"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:id="@+id/dojoico"
            android:src="@drawable/dojoico" />

        <ImageButton
            android:scaleType="fitCenter"
            android:id="@+id/alquimiaico"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:src="@drawable/alquimiaico" />

    </LinearLayout>

</RelativeLayout>


Solution

  • Add android:background="@android:color/transparent" to you ImageButtons