Dante Paniccia
Dante Paniccia

Reputation: 31

Skipped 66 frames! The application may be doing too much work on its main thread

So, I have an activity with Image Buttons and TextViews inside of a CardView. For some reason whenever I try to open the activity within the app it takes awhile for it to open and in the console it gives me this message: Skipped 66 frames! The application may be doing too much work on its main thread. When I remove the image buttons the activity loads up normally? Does anyone know why?

`

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        >

        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            card_view:cardCornerRadius="4dp"
            card_view:cardElevation="10dp"
            >

            <TextView
                android:id="@+id/info_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Locanda La Sementa"
                android:padding="8dp"
                android:background="#424242"
                android:textColor="@android:color/white"
                android:layout_alignParentBottom="true"
                android:gravity="bottom"
                />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="170dp"
                android:src="@drawable/semanta"
                android:scaleType="fitXY"
                android:id="@+id/semata"
                android:background="@null"
                />

        </android.support.v7.widget.CardView>


        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view2"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            card_view:cardCornerRadius="4dp"
            card_view:cardElevation="10dp"
            android:layout_below="@+id/card_view"
            >

            <TextView
                android:id="@+id/info_text3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="L’Altro Frantoio"
                android:padding="8dp"
                android:background="#424242"
                android:textColor="@android:color/white"
                android:layout_alignParentBottom="true"
                android:gravity="bottom"
                />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="170dp"
                android:src="@drawable/fran"
                android:scaleType="centerCrop"
                android:id="@+id/frantoio"
                android:background="@null"
                />

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view3"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            card_view:cardCornerRadius="4dp"
            card_view:cardElevation="10dp"
            android:layout_below="@+id/card_view2"
            >

            <TextView
                android:id="@+id/info_text2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Domus Hernica"
                android:padding="8dp"
                android:background="#424242"
                android:textColor="@android:color/white"
                android:layout_alignParentBottom="true"
                android:gravity="bottom"
                />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="170dp"
                android:src="@drawable/ernica"
                android:scaleType="centerCrop"
                android:id="@+id/ernica"
                android:background="@null"
                />

        </android.support.v7.widget.CardView>


        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view4"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            card_view:cardCornerRadius="4dp"
            card_view:cardElevation="10dp"
            android:layout_below="@+id/card_view3"
            >

            <TextView
                android:id="@+id/info_text4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Pizzeria la Ciocia"
                android:padding="8dp"
                android:background="#424242"
                android:textColor="@android:color/white"
                android:layout_alignParentBottom="true"
                android:gravity="bottom"
                />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="170dp"
                android:src="@drawable/ciocia"
                android:scaleType="centerCrop"
                android:id="@+id/ciocia"
                android:background="@null"
                />

        </android.support.v7.widget.CardView>


        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view6"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            card_view:cardCornerRadius="4dp"
            card_view:cardElevation="10dp"
            android:layout_below="@+id/card_view4"
            >

            <TextView
                android:id="@+id/info_text6"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="L'Aia Antica"
                android:padding="8dp"
                android:background="#424242"
                android:textColor="@android:color/white"
                android:layout_alignParentBottom="true"
                android:gravity="bottom"
                />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="170dp"
                android:src="@drawable/laia_antica"
                android:scaleType="centerCrop"
                android:id="@+id/antica"
                android:background="@null"
                />

        </android.support.v7.widget.CardView>

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:height="80dp"
            android:text="More"
            android:textSize="17dp"
            android:id="@+id/more_Button"
            android:layout_below="@+id/card_view6"
            android:background="#424242"
            android:textColor="@android:color/white"
            />

    </RelativeLayout>
</ScrollView>

`

Upvotes: 2

Views: 945

Answers (3)

SWAppDev
SWAppDev

Reputation: 248

I have avoided this issue by not using the xml src tag but setting the imageviewers bitmap programatically.,

Upvotes: 0

JohanShogun
JohanShogun

Reputation: 2976

If you aren't using your RelativeLayout to place your children relative to each other in a non linear way consider using a LinearLayout instead. A RelativeLayout requires two layout passes to layout its content.

Also, you may want to move some views into ViewStubs if they are not displayed immediately.

Upvotes: 0

Gil Vegliach
Gil Vegliach

Reputation: 3562

In the ImageButtons, the images might be too large, there might be too many images or a combination of the two. The xml attribute android:src uses ImageView.setImageResource() which does the decoding on the UI thread. Notice also the an ImageButton is-a ImageView.

See also the docs.

Upvotes: 1

Related Questions