Slow rendering of the easiest layout

In my Android apps, 30% of my users experience slow rendering. My application has a rather complicated interface, so I did a really basic project to try and solve this problem. But this turns out to be pretty slow even with the simplest layouts.

A layout is centered text that Android Studio offers as a template:

<?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"
    tools:context="slowrenderingtest.pichaipls.com.slowrenderingtest.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/timerView"
        android:text="00:00"
        android:textSize="40dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

Activity using the layout changes the text every second (because it's a timer):

Timer updateTicks = new Timer();
updateTicks.scheduleAtFixedRate(new TimerTask() {
    @Override
    public void run() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Random r = new Random();
                timerView.setText(String.format("%02d", r.nextInt(60))+":"+
                                    String.format("%02d", r.nextInt(60)));
            }
        });
    }
}, 100, 1000);

GPU, 16 (-, 30% ). TextView. : , , . ( ), . , , CPU/GPU ( ).

- Android. ( , - 5% , , ), , . , , Android .

- ?

+4
2

, , - ?

. Runnable, TextView () Handler. TextView RecyclerView. , , - , ( , - , ), 16 . bam, 30-50 .

, SO . wrap_content match_parent. . 1000 500, 200, 100, 50, 20, 16, 10 16/10 ( ?).

. , , , ?

Android Studio, , CPU , . ( - Nexus 5). enter image description here

, , GPU Rendering, 16 ! , . ( - ). enter image description here

+3

textView match_parent ... , , TextView . ...

0

Source: https://habr.com/ru/post/1687979/


All Articles