0

I have a fragment (part of jetpack navigation graph) with RecyclerView (it's a 2 by 10 vertical grid), 1 card is ConstraintLayout (1 TextView Title and 2 TextView SubTitle + 1 ImageView 64x64dp, using pngs approx 10kb each)

Problem is the frame according to android studio systrace (CPU->Trace System Calls) takes 160-250ms. I'm testing on Android 10, Xiaomi Note 9 Pro (6G ram, SG 720G), started from android profile button.

1 card layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/id1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:background="@drawable/card_background"
android:layout_margin="8dp"
android:elevation="2dp"
android:foreground="@drawable/btn_background_ripple">

<TextView
    android:id="@+id/tvTitle"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:fontFamily="@font/roboto"
    android:gravity="center_horizontal"
    android:lineSpacingExtra="3sp"
    android:textColor="@android:color/black"
    android:textSize="16sp"
    app:layout_constraintBottom_toTopOf="@+id/tvSubTitle"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/iv"
    app:layout_constraintVertical_bias="0.0"
    app:layout_constraintVertical_chainStyle="packed" />

<TextView
    android:id="@+id/tvSubTitle"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="20dp"
    android:fontFamily="@font/roboto"
    android:gravity="center_horizontal"
    android:lineSpacingExtra="3sp"
    android:textColor="@android:color/black"
    android:textSize="14sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvTitle"
    tools:text="Vocabulario" />

<ImageView
    android:id="@+id/iv"
    android:layout_width="64dp"
    android:layout_height="64dp"
    android:layout_marginTop="16dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    />


 </androidx.constraintlayout.widget.ConstraintLayout>

Screenshot of stacktrace

stacktrace]1

toasty
  • 142
  • 1
  • 1
  • 10
  • i dont see any problem with your xml layout, try loading images using Glide – ilaimihar Sep 09 '20 at 10:38
  • @ilaimihar i tried actually using coil (with both svg and png), images are local in drawable folder – toasty Sep 09 '20 at 11:37
  • I do see some problems with your layout, interesting that the other user didn't. For instance; draweable background, a chain, the entire layout has wrap height, so it needs to measure everything before it can say "this is my final size". The Image is fixed, but the textViews aren't (so a text measure pass.. costly!). TextViews don't have `constrainedHeight=true` either, which can cause problems. You have start/left, end/right duplicates (not an issue but useless for API 16+), there's custom fonts, biasing, margins, and etc. The alignParentTop/bottm are useless (RelativeLayout!). – Martin Marconcini Sep 09 '20 at 11:50
  • You also mention "1 card is ConstraintLayout" is this a CardView? Or is that the layout of your recyclerView? Also, post the (relevant) layout of the RecyclerView, it also participates in determining how much space that RV will have to begin with... all in all however, it's hard to tell if you're having a CL issue or it's just poor layout optimization here. What version of CL are you using? Mention that too. – Martin Marconcini Sep 09 '20 at 11:51

1 Answers1

0

To find out what's contributing to the long Choreographer#doFrame call in System Trace, you can zoom in further and see what each inflate trace event consists of. You should be able to map those trace events (currently too small to see in your screenshot) to individual elements in the XML layout.

Yi Yang
  • 421
  • 2
  • 6