2014-12-31 71 views
0

我對某些具有不同鍵盤的手機有一個奇怪的問題,那就是我想知道是否有人遇到過並且有解決方案的Google/Samsung。軟鍵盤重繪性能問題

我遇到的問題是:如果我使用股票谷歌或三星銀河的鍵盤,我的佈局(下圖)表現良好,活潑,沒有任何滯後。我在很多設備上進行了測試(Galaxy S3,Galaxy Note,Galaxy S5,Nexus 5,6和7)。如果我使用默認鍵盤在HTC或LG手機上運行此功能,則佈局在用戶輸入文本時會出現可見的滯後現象。

經過大量調試和性能測量後,我發現問題出在建議欄上。對於默認的三星/谷歌鍵盤,建議欄總是存在(如下所示),但對於HTC/LG手機,只有在用戶鍵入導致佈局重新呈現的內容時,纔會顯示建議欄。當用戶開始輸入時,這種重新渲染會導致明顯的延遲。我已經嘗試了許多在這裏找到的解決方案,比如將我的佈局封裝在LinearLayout中,並修改其寬度(通過指定權重)並固定其他控件的高度等(在下面的佈局文件中都可見),以便移除測量佈局測量的負擔,但他們都沒有消除這種滯後。

我的問題是,我將如何解決這個問題?有沒有辦法強制所有鍵盤始終顯示此建議欄,而不管用戶是否輸入任何文字?對我來說,強迫用戶選擇特定的鍵盤不是一個真正的選擇,否則他們會面臨相當大的延遲。

Google keyboard suggestion bar

我的佈局是一個簡單的佈局,水平滾動視圖和兩個編輯文本:

<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> 

清單中的活動是這樣的:

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

更新: 我注意到WhatsApp總是在鍵盤上顯示這個建議欄,即使EditText的輸入是空的(用戶還沒有輸入值)。有誰知道這是怎麼完成的?

非常感謝提前。

+0

HTC默認採用非常主動的省電模式。你有沒有試過關閉節電功能? –

回答

0

以下設置將隱藏建議欄。但是,我不知道有什麼設置來強制它顯示。

android:inputType="textNoSuggestions" 
android:inputType="textFilter" 
+0

我不害怕。我*希望*有自動更正建議。無論所有鍵盤上是否有文字輸入,我都想顯示建議欄。谷歌和三星鍵盤可以做到這一點。 LG和HTC沒有。 – kha

+0

啊,對不起。請重新閱讀您的請求。你想強制它顯示。這沒有框架屬性。你做的任何事情都會有點破綻。 –

+0

:)沒問題。黑客也可以。這個問題使我瘋狂。任何建議將非常感激。 – kha

1

有沒有辦法強制它。這是必須在鍵盤上完成的,因爲鍵盤決定何時顯示candidatesView。事實上,這個性能問題是爲什麼在我工作的幾個鍵盤上,我們沒有使用內置在candidatesView功能中的Android,並且推出了我們自己的。

+0

謝謝。這很不幸,雖然我注意到WhatsApp在輸入文本時總是顯示此欄(即使文本框爲空,它也會隨機添加一些單詞)。你知道這是做什麼? – kha

+0

我的猜測是它正在產生它自己的建議。一個應用程序可以做到這一點,廣告的鍵盤應該顯示出來,儘管不是全部。 –

+0

謝謝。我會嘗試一下。 – kha