简体   繁体   English

软键盘重绘性能问题

[英]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. 对于某些键盘与Google /三星不同的手机,我遇到了一个奇怪的问题,我想知道是否有人遇到过并找到了解决方案。

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. 我遇到的问题是:如果我使用普通的google或Samsung galaxy的键盘,则我的布局(如下所示)效果很好,很敏捷,并且没有滞后。 I tested this on many devices (Galaxy S3, Galaxy Note, Galaxy S5, Nexus 5, 6 and 7). 我在许多设备(Galaxy S3,Galaxy Note,Galaxy S5,Nexus 5、6和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. 另一方面,如果我使用默认键盘在HTC或LG手机上运行它,则用户输入文本时,布局会有明显的滞后。

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. 对于默认的Samsung / Google键盘,建议栏始终存在(如下所示),但对于HTC / LG手机,建议栏仅在用户键入会导致重新呈现布局的内容后才可见。 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. 我已经尝试过许多在SO上找到的解决方案,例如将我的布局包装在LinearLayout中并固定其宽度(通过指定权重)和固定其他控件的高度等(都在下面的布局文件中可见)以删除测量布局测量的负担,但没有一个可以消除这种滞后。

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键盘建议栏

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). 更新:我注意到WhatsApp始终在键盘上显示此建议栏,即使EditText的输入为空(用户尚未输入值)。 Does anyone know how that's done? 有人知道这是怎么做的吗?

Many thanks in advance. 提前谢谢了。

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. 实际上,这个性能问题是为什么我使用的多个键盘上的我们没有使用内置的候选人查看功能的Android并推出了自己的功能的原因。

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM