2015-09-04 30 views
2

时调整的问题,我使用被拉伸以适应屏幕,其中行每个键采用宽度KeyboardView旋转

android:keyWidth="33%p" 
android:keyHeight="@dimen/key_height" 

的1/3来处理方向改变的宽度,键盘视图片段我设置了一个新的键盘:

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    // Required to force the keyboard to inflate correctly after a rotation 
    KeyboardView keyboardView = (KeyboardView) getView().findViewById(R.id.keyboard); 
    keyboardView.setKeyboard(new Keyboard(getActivity(), R.xml.keyboard_config)); 
} 

这工作正常。我现在想要使用不同的keyHeight用于纵向和横向。当我添加这个时,键的高度在方向改变时正确调整大小,但键盘不再填满横向中的屏幕宽度。或者使片段的视图无效并不能解决问题。

回答

0

我使用键高度的百分比值解决了此问题,并在onEvaluateFullscreenMode事件中重新创建/重新键入键盘。下面的例子。

XML

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
      encoding="UTF-16" 
      android:keyWidth="20%p" 
      android:keyHeight="8%p" 
    > 
    : 
    : 
</Keyboard> 

的Java

@Override 
public boolean onEvaluateFullscreenMode() { 

    try { 

     keyboardView.setKeyboard(new Keyboard(getActivity(), R.xml.keyboard_config)); 

    } catch (Exception e) { 

     Log.e(TAG, "onEvaluateFullscreenMode: Failed to recreate keyboard.", e); 
    } 

    return this.isFullscreenMode(); 
}