kha
kha

Reputation: 20003

Soft Keyboard redraw performance issue

I'm having a strange problem with certain phones with different keyboards to that of Google/Samsung that I was wondering if anyone had encountered and had a solution for.

The problem I'm encountering is this: If I use the stock google or Samsung galaxy's keyboard, my layout (below) performs fine, is snappy and there are no lags whatsoever. I tested this on many devices (Galaxy S3, Galaxy Note, Galaxy S5, Nexus 5, 6 and 7). If I run this on an HTC or an LG phone on the other hand with their default keyboard, the layout has a visible lag when users enter text.

After lots of debugging and performance measurements, I found out that the problem is with the suggestion bar. For the default Samsung/Google keyboards, the suggestion bar is always present (shown below) but for the HTC/LG phones, the suggestion bar only becomes visible once the user types something which causes a re-render of the layout. This re-render in turn causes noticeable lag when the user starts typing. I've tried many, many solutions found here on SO such as wrapping my layouts in LinearLayout and fixing their widths (by specifying weights) and fixing heights of other controls, etc (all visible in the layout file below) in order to remove the burden of measuring the layout measurements but none of them have removed this lag.

My question is, how would I fix this problem? Is there a way to force ALL keyboards to always show this suggestion bar regardless of the fact that there may or may not be any text entered by the user? It's not really an option for me to force my users to choose a specific keyboard or else they face considerable lag.

Google keyboard suggestion bar

My layout is a simple layout with a horizontal scroll view and two edit texts:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:text="@string/editText_topic"
        android:textSize="@dimen/txt_description_font_size" />

    <HorizontalScrollView
        android:id="@+id/layout_topics"
        android:layout_width="match_parent"
        android:layout_height="@dimen/gallery_height"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="2dp"
        android:background="@drawable/rectangle_error_background"
        android:paddingLeft="6dp"
        android:paddingRight="6dp" >

        <LinearLayout
            android:id="@+id/gallery_topic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:animateLayoutChanges="true"
            android:orientation="horizontal" />
    </HorizontalScrollView>

    <RelativeLayout
        android:id="@+id/layout_title_text"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginTop="8dp" >

        <TextView
            android:id="@+id/txt_title_length"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textSize="@dimen/length_text_font_size" >
        </TextView>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/txt_title"
            android:layout_width="0dp"
            android:layout_height="@dimen/txt_input_height"
            android:layout_gravity="fill_horizontal|fill_vertical"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:hint="@string/editText_title_hint"
            android:inputType="textFilter|textCapSentences" >

            <requestFocus
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </EditText>
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/layout_description_text"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginTop="8dp" >

        <TextView
            android:id="@+id/txt_description_length"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textSize="@dimen/length_text_font_size" >
        </TextView>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/txt_content"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="top|left"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:gravity="top"
            android:hint="@string/editText_description_hint"
            android:inputType="textAutoCorrect|textCapSentences|textMultiLine"
            android:scrollbars="vertical" >
        </EditText>
    </LinearLayout>
</LinearLayout>

The activity in manifest is this:

    <activity
        android:name="MyActivity"
        android:icon="@drawable/whatever"
        android:label="@string/empty"
        android:parentActivityName="ParentActivity"
        android:theme="@style/MyTheme"
        android:windowSoftInputMode="adjustResize|stateVisible" >
    </activity>

Update: I've noticed WhatsApp always shows this suggestion bar on the keyboards even though the EditText's input is empty (user has not yet entered a value). Does anyone know how that's done?

Many thanks in advance.

Upvotes: 0

Views: 690

Answers (2)

Gabe Sechan
Gabe Sechan

Reputation: 93561

There is no way to force it. That's something that has to be done on the keyboard side, as the keyboard decides when to show the candidatesView. In fact this performance issue is a reason why on several of the keyboards I worked on we didn't use the Android built in candidatesView functionality and rolled our own.

Upvotes: 1

Jason Williams
Jason Williams

Reputation: 2860

The following settings will hide the suggestion bar. However, I do not know a setting to force it to show.

android:inputType="textNoSuggestions"
android:inputType="textFilter"

Upvotes: 0

Related Questions