-1

When I add ImageButtons to my app (they don't have background), the app crashes. I have following code:

<ImageButton
    android:id="@+id/ib_main_home"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/home"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:id="@+id/ib_main_categories"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/categories"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:id="@+id/ib_main_actors"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/actors"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/twitter"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/facebook"
    android:background="@null"
    android:scaleType="fitCenter"
    />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/instagram"
    android:background="@null"
    android:scaleType="fitCenter"
    />

(Whole xml is in RelativeLayout)... Without @null, image shows bigger than the screen. And Button fills the whole screen. Anyone can help me?

Dhruv Patel
  • 1,529
  • 1
  • 18
  • 27
Katona Tamás
  • 15
  • 1
  • 4

2 Answers2

0

According to your comment that the error is java.lang.OutOfMemoryError, I suspect one or more of the images you are trying to load to the background take too much memory becuase they are too big. The easiest solution will be to resize the images to a smaller size (and by this also lower your app's size). You can resize manually or use one of the solutions offered online such as : http://resizeimage.net/

Yovboy
  • 85
  • 7
0

For better result remove wrap_content and scale the images your self. You can shrink size of your source image.If you removed wrap_content also remove background="@null" this may help you. Please tell me how do you want to organize these ImageViews. You can user 'merge' tag for creating compound views , also see this link.

mmdreza baqalpour
  • 1,106
  • 9
  • 18