-1

i have a activity with RelativeLayout in which there is a FrameLayout and in FrameLayout there are 15 ImageButtons. App crashes whenever that activity loads. here is my xml code.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fitsSystemWindows="true" >
    <FrameLayout
            android:id="@+id/bodyFrontView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/bodyFrontBtn"
            android:layout_marginBottom="50dp"
            android:layout_alignParentLeft="true">
            <ImageButton
               android:id="@+id/head"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="@null"
               android:contentDescription="@string/app_name"
               android:scaleType="centerInside"
               android:layout_gravity="center"
               android:src="@drawable/head"
                android:clickable="false"
                android:focusable="false"/>
... so on 14
    </FrameLayout>
    </RelativeLayout>

i havent even use anything in my java file yet. but still it crashes as soon activity loads.

here is my logcat actually some of it

09-28 18:25:12.487 5391-5391/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.proximatesolutions.daralhajama, PID: 5391
    java.lang.RuntimeException: Canvas: trying to draw too large(189422496bytes) bitmap.
        at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:229)
        at android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)
        at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:529)
        at android.widget.ImageView.onDraw(ImageView.java:1367)
        at android.view.View.draw(View.java:20352)
        at android.view.View.updateDisplayListIfDirty(View.java:19297)

100 more lines like this

WaqasArshad
  • 237
  • 1
  • 3
  • 12

2 Answers2

2

Remove android:background="@null" from all ImageButton

Problem is your images are too large in terms of resolution or size. Now you can do two things:

  1. Load image of low resolution(matching with height or width of image button) and small in size

  2. Use Glide library to load images to ImageButton, It will change resolution according to view in which you want to display image.

Add this in build.gradle (app level) inside dependencies block

 compile 'com.github.bumptech.glide:glide:3.7.0'

sync you project.

then in you activity on create :

 Glide.with(this).load(R.drawable.bg).into(imageButton);

Use option 2 it will work definitely.

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
0

You need to resize your images to fit in memory or you can use below method to set images efficiently without resizing.

https://developer.android.com/topic/performance/graphics/load-bitmap

Sunny
  • 14,522
  • 15
  • 84
  • 129