0

I'm having a problem trying to use image buttons in my layout. Everything's ok when I add the first image button, but when I add the second one the first one shrinks, does it depend on the layout that I'm using? I have a relative layout set up but I don't know how to keep every button with the same size.

<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"
tools:context="com.example.supernovastudios.conguate.preguntas3"
android:background="#222222">


<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton5"
    android:background="@drawable/botonpregunta"
    android:layout_centerHorizontal="true" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/botonpregunta"
    android:id="@+id/imageButton6"
    android:layout_alignTop="@+id/imageButton5"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="143dp" />

<ImageButton
    android:layout_width="wrap_content"
    android:background="@drawable/botonpregunta"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton7"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="104dp" />

enter image description here

That's a picture of the layout. The button in the middle is the only one that keeps it's original size and the others seem to shrink when I move them up or down.

1 Answers1

0

you are using image as background in your ImageButtons.

you should use image as src in ImageButton

example:

<ImageButton
    android:id="@+id/imageButton5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitCenter" 
    android:adjustViewBounds="true"
    android:src="@drawable/botonpregunta" />
Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78