我一直在尝试为我的Android自定义键盘IME添加滚动视图,但是到目前为止,我尝试的所有方法都没有起作用。
这是我的代码的一部分:
keyboard.xml
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboard"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarStyle="insideOverlay"
android:scrollbars="horizontal"
android:focusable="true"
/>
</ScrollView>
.java
@Override
public View onCreateInputView() {
context = getApplicationContext();
ScrollView scroll = (ScrollView)getLayoutInflater().inflate(R.layout.keyboard,null);
kv = (KeyboardView)scroll.findViewById(R.id.keyboard);
keyboard = new Keyboard(this, R.xml.qwerty);
kv.setPreviewEnabled(false);
kv.setKeyboard(keyboard);
kv.setHorizontalScrollBarEnabled(true);
kv.canScrollHorizontally(1);
kv.setOnKeyboardActionListener(this);
return kv;
}
我得到了以下错误
> java.lang.IllegalStateException: The specified child already has a
> parent. You must call removeView() on the child's parent first.
预期效果:像下面的图片滚动(无法在此处上传图片,看起来我的声望还不够 :))
http://www.fandroides.com/wp-content/uploads/2014/04/Google-keyboard-emojis.png
任何帮助都将不胜感激。谢谢。