2012-08-07 22 views
3

我正在custome鍵盤上。我已經setCandidatesViewShown(true)函數onCreateCandidatesView(),問題是UI無法正確重新調整。調整用戶界面與候選人可見在自定義鍵盤

任何援助將不勝感激..下面是我做了什麼

@Override 
public View onCreateCandidatesView() {  

    LayoutInflater li = (LayoutInflater) getApplicationContext() 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View wordBar = li.inflate(R.layout.wordbar, null); 
    LinearLayout ll = (LinearLayout) wordBar.findViewById(R.id.words); 
    Button voiceCmd = (Button) wordBar.findViewById(R.id.voiceword); 
    LinearLayout ll1 = null; 
    Button voiceCmd1 = null; 
    //comment this block in the event of showing only one keyboard so that we can only 
    //one autocorrect bar 
    if (isLargeScreen) { 
     ll1 = (LinearLayout) wordBar.findViewById(R.id.words1); 
     voiceCmd1 = (Button) wordBar.findViewById(R.id.voiceword1); 
    } 

    voiceCmd.setOnClickListener(voiceClickListener); 

    mCandidateView = new CandidateView(this); 
    mCandidateView.setService(this); 
    setCandidatesViewShown(true); 
    mCandidateView.setLayoutParams(new LayoutParams(
      LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 

    ll.addView(mCandidateView);    

    return wordBar; 

} 

回答

9

我有同樣的問題。我在Ced here的帖子上找到了答案。

解決的辦法是添加到您的輸入法服務,

@Override public void onComputeInsets(InputMethodService.Insets outInsets) { 
    super.onComputeInsets(outInsets); 
    if (!isFullscreenMode()) { 
     outInsets.contentTopInsets = outInsets.visibleTopInsets; 
    } 
} 

這是故意的候選視圖不向上推應用。從doc

注意,由於候選觀點趨於顯示和隱藏了很多,它不會以同樣的方式作爲軟輸入視圖影響應用程序的用戶界面:它會不會導致應用程序窗口調整,只有在需要用戶查看當前焦點時才導致它們被平移。

上面的黑客增加了「內容」區域以包括候選視圖區域。 onComputeInsets的文檔將幫助你理解這個概念。

計算您的UI中有趣的插圖。默認實現使用可見插圖的候選幀的頂部,以及內容插入的輸入幀的頂部。

+0

Thankx!它的舊的,必須重新看到你的答案是有幫助的:) – voidRy 2014-03-23 06:42:30

+0

這是用於Portait Android應用程序,但在景觀不工作這種方法任何建議 – 2014-11-18 14:39:34