XML : Android ImageButton doing way too much work on the main thread

My layout was perfectly fine until I added 4 ImageButton into the XML. The goal was for each of my 4 regular Button to have a little "settings" imagebutton on the upper-right hand side, where users could edit a button's textview.

Upon adding even one ImageButton, it gets extremely laggy and the logcat is telling me there is too much work on the main thread, skipping ~200 frames.

I'm looking for an answer as to why my solution makes it so laggy, and if there is a better way to go about the problem.

Snippet of XML below:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent" android:layout_height="match_parent"      android:orientation="vertical"      >          <ImageView              android:layout_width="match_parent"              android:layout_height="8dp"                android:id="@+id/imageView"              android:src="@drawable/male"              android:layout_weight="67"              />      <TableLayout            android:layout_width="match_parent"          android:layout_height="0dp"          android:layout_weight="33"          >          <TableRow                android:layout_width="fill_parent"              android:layout_height="fill_parent"              android:layout_weight="1">              <RelativeLayout                  android:layout_weight="1">              <Button                  android:layout_width="match_parent"                  android:layout_height="match_parent"                  android:text="@string/pushups"                  android:id="@+id/pushup_button"                  android:onClick="DoPushups"                  android:background="@drawable/pushup_button_details"                  android:layout_margin="3dp" />                  <ImageButton                      android:layout_width="wrap_content"                      android:layout_height="wrap_content"                      android:layout_alignParentTop="true"                      android:layout_alignParentRight="true"                      android:layout_alignParentEnd="true"                      android:src="@drawable/settings_icon"                      android:background="@drawable/settings_button_details"/>                </RelativeLayout>              <RelativeLayout                  android:layout_weight="1">              <Button                    android:layout_width="match_parent"                  android:layout_height="match_parent"                  android:text="@string/squats"                  android:id="@+id/squat_button"                  android:background="@drawable/squat_button_details"                  android:onClick="DoSquats"                  android:layout_margin="3dp"/>                  <ImageButton                      android:layout_width="wrap_content"                      android:layout_height="wrap_content"                      android:layout_alignParentTop="true"                      android:layout_alignParentRight="true"                      android:layout_alignParentEnd="true"                      android:src="@drawable/settings_icon"                      android:background="@drawable/settings_button_details"/>              </RelativeLayout>          </TableRow>            <TableRow              android:layout_width="match_parent"              android:layout_height="match_parent"              android:layout_weight="1">                <RelativeLayout                  android:layout_weight="1">                  <Button                      android:layout_width="match_parent"                      android:layout_height="match_parent"                      android:text="@string/planks"                      android:id="@+id/plank_button"                      android:onClick="DoPlanks"                      android:background="@drawable/plank_button_details"                      android:layout_margin="3dp"/>                  <ImageButton                      android:layout_width="wrap_content"                      android:layout_height="wrap_content"                      android:layout_alignParentTop="true"                      android:layout_alignParentRight="true"                      android:layout_alignParentEnd="true"                      android:src="@drawable/settings_icon"                      android:background="@drawable/settings_button_details"/>              </RelativeLayout>                <RelativeLayout                  android:layout_weight="1">                  <Button                      android:layout_width="match_parent"                      android:layout_height="match_parent"                      android:text="Sit-Ups"                      android:id="@+id/button"                      android:layout_gravity="bottom"                      android:onClick="DoSitups"                      android:layout_margin="3dp"                      android:background="@drawable/situp_button_details" />                  <ImageButton                      android:layout_width="wrap_content"                      android:layout_height="wrap_content"                      android:layout_alignParentTop="true"                      android:layout_alignParentRight="true"                      android:layout_alignParentEnd="true"                      android:src="@drawable/settings_icon"                      android:background="@drawable/settings_button_details"/>              </RelativeLayout>          </TableRow>            </TableLayout>    </LinearLayout>    

No comments:

Post a Comment