-2

Here's the xml code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
  >


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/backgound"
        android:orientation="vertical">



        <TextView
            android:id="@+id/txt1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"

            android:text="Welcome to Ordering Menu"
            android:textColor="@android:color/black"
            android:textSize="25sp"
             />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_height="wrap_content"
            android:orientation="vertical">



            <Button
                android:id="@+id/btn2"
                android:layout_width="48dp"
                android:layout_height="48dp"

                android:layout_marginTop="20dp"
                android:onClick="increase"
                android:text="+"
                android:textColor="@android:color/black"/>




            <TextView

                android:id="@+id/quantity_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="0"
                android:textSize="20sp"
             />

            <Button
                android:id="@+id/btn3"
                android:layout_width="50dp"
                android:textColor="@android:color/black"
                android:layout_height="50dp"

                 android:layout_marginTop="20dp"
                android:onClick="decrease"
                android:textSize="30sp"
                android:text="-" />


        </LinearLayout>


        <TextView

            android:id="@+id/kk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Price" />

        <TextView
            android:id="@+id/price_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp"
            android:text="$0"
            android:textColor="#000000" />


        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="15dp"
            android:onClick="submitOrder"
            android:text="ORDER" />


    </LinearLayout>

</android.support.constraint.ConstraintLayout>

XML code when I use color as a background:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
  >


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/holo_blue_light"
        android:orientation="vertical">



        <TextView
            android:id="@+id/txt1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"

            android:text="Welcome to Ordering Menu"
            android:textColor="@android:color/black"
            android:textSize="25sp"
             />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_height="wrap_content"
            android:orientation="vertical">



            <Button
                android:id="@+id/btn2"
                android:layout_width="48dp"
                android:layout_height="48dp"

                android:layout_marginTop="20dp"
                android:onClick="increase"
                android:text="+"
                android:textColor="@android:color/black"/>




            <TextView

                android:id="@+id/quantity_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="0"
                android:textSize="20sp"
             />

            <Button
                android:id="@+id/btn3"
                android:layout_width="50dp"
                android:textColor="@android:color/black"
                android:layout_height="50dp"

                 android:layout_marginTop="20dp"
                android:onClick="decrease"
                android:textSize="30sp"
                android:text="-" />


        </LinearLayout>


        <TextView

            android:id="@+id/kk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Price" />

        <TextView
            android:id="@+id/price_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp"
            android:text="$0"
            android:textColor="#000000" />


        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="15dp"
            android:onClick="submitOrder"
            android:text="ORDER" />


    </LinearLayout>

</android.support.constraint.ConstraintLayout>
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64

1 Answers1

2

You mention in the comments that the background image you are using is 1600 x 2560 pixels in size. All images are inflated as bitmaps when rendered onto the screen, so making a rough calculation from this answer against an image with those dimensions, that's 1600 * 2560 * 3 bytes, which is 11.71 Megabytes minimum on a single image.

Taking a guess that your app has a total of 16-32MB of RAM available to it based on this answer, you're using a very significant chunk of that memory with this one image.You will need to reduce the dimensions of this image using an image editor and replace it in your app's res/drawable folder. By how much I can't say, it's a trade-off between image dimensions and the quality of that image once it's rendered on your device.

I would recommend reading the Android documentation about supporting bitmaps on different screen densities so that you can provide the best image quality on a per-device basis without running into this issue again.

Michael Dodd
  • 10,102
  • 12
  • 51
  • 64