Android Studio ScrollView Crashes the app

  • Replies:0
Katona Tamas
  • Forum posts: 1

Dec 27, 2017, 11:52:07 PM via Website

When I using *ScrollView* it works with 5 *ImageButtons*, but if I try to add a new one, it crashes with "OutofMemory error", this is weird, because when I re-used the buttons, that's I used before, and it worked fine, and I don't know how. The all images are the same resoultion (530x143), with transparent background.

Here's my .xml, I hope you can help me:

.xml:

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageButton
        android:id="@+id/cat_ib1"
        android:layout_width="235sp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="71dp"
        android:background="@android:color/transparent"
        android:scaleType="fitCenter"
        android:src="@drawable/categories_action" />

    <ImageButton
        android:id="@+id/cat_ib2"
        android:layout_width="235sp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/cat_ib1"
        android:layout_below="@+id/cat_iv_csik"
        android:layout_marginTop="56dp"
        android:background="@android:color/transparent"
        android:scaleType="fitCenter"
        android:src="@drawable/categories_adventure" />

    <ImageButton
        android:id="@+id/cat_ib3"
        android:layout_width="235sp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/cat_ib2"
        android:layout_below="@+id/cat_ib1"
        android:layout_marginTop="25dp"
        android:background="@android:color/transparent"
        android:scaleType="fitCenter"
        android:src="@drawable/categories_animation" />

    <ImageButton
        android:id="@+id/cat_ib4"
        android:layout_width="235sp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/cat_ib3"
        android:layout_below="@+id/cat_ib2"
        android:layout_marginTop="25dp"
        android:background="@android:color/transparent"
        android:scaleType="fitCenter"
        android:src="@drawable/categories_anime" />

    <ImageButton
        android:id="@+id/cat_ib5"
        android:layout_width="235sp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/cat_ib4"
        android:layout_below="@+id/cat_ib3"
        android:layout_marginTop="25dp"
        android:background="@android:color/transparent"
        android:scaleType="fitCenter"
        android:src="@drawable/categories_biography" />

    <ImageButton
    android:id="@+id/cat_ib6"
    android:layout_width="235sp"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/cat_ib5"
    android:layout_below="@+id/cat_ib4"
    android:layout_marginTop="25dp"
    android:background="@android:color/transparent"
    android:scaleType="fitCenter"
    android:src="@drawable/categories_cartoon" />

    <ImageButton
        android:id="@+id/cat_ib7"
        android:layout_width="235sp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/cat_ib6"
        android:layout_below="@+id/cat_ib5"
        android:layout_marginTop="25dp"
        android:background="@android:color/transparent"
        android:scaleType="fitCenter"
        android:src="@drawable/categories_comedy" />

    <ImageButton
        android:id="@+id/cat_ib8"
        android:layout_width="235sp"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/cat_ib7"
        android:layout_below="@+id/cat_ib6"
        android:layout_marginTop="25dp"
        android:background="@android:color/transparent"
        android:scaleType="fitCenter"
        android:src="@drawable/categories_crime_gangster" />

    <ImageView
        android:id="@+id/cat_iv_csik"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/csik" />


</RelativeLayout>

After the cat_ib5 button, whenever I try to add an another ImageButton the app goes crash. (The whole code is in RelativeLayout).

Reply