5

I have a Custom View which is extends from LinearLayout. In the init{} I call the inflate function to inflate my layout.

inflate(context, R.layout.base_layout, this)

I logged the inflating speed, like this:

// Log.
inflate(context, R.layout.base_layout, this)
// Log

It takes 1ms to inflate the layout. Awesome! But when my layout have a TextInputLayout than it increases to 120ms

My layout:

<?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"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/randomName2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/randomName"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" >

        <android.support.design.widget.TextInputLayout
            android:id="@+id/randomName4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:paddingTop="8dp">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/randomName3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text" />

        </android.support.design.widget.TextInputLayout>


    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/randomName"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginBottom="4dp"
        android:gravity="bottom"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="@id/randomName2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@id/randomName2"/>

</android.support.constraint.ConstraintLayout>

How can I fix this 120ms issue? This creates FPS lag when my fragment creating.

Thank you for any suggestion.

vihkat
  • 895
  • 3
  • 13
  • 28

0 Answers0