vertical studio linearlayout horizontal funciona como agregar java android keyboard scrollview ime

java - studio - scrollview eclipse android



Cómo agregar scrollview a keyboardView en android (1)

He estado tratando de agregar scrollview a mi teclado personalizado de Android Ime, pero nada he intentado hasta ahora.

Aquí hay parte de mi código

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

Aparece el siguiente error

> java.lang.IllegalStateException: The specified child already has a > parent. You must call removeView() on the child''s parent first.

Esperado: desplácese como la imagen a continuación (no se puede cargar aquí, parece que mi reputación no es suficiente para eso :))

http://www.fandroides.com/wp-content/uploads/2014/04/Google-keyboard-emojis.png

Cualquier ayuda será apreciada. Gracias


Intenta hacer este cambio:

keyboard.xml

<?xml version="1.0" encoding="utf-8"?> <android.inputmethodservice.KeyboardView android:id="@+id/keyboard" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" />

my_layout.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/keyboard_layout"> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="@dimen/example_height" android:id="@+id/keyboard_scroll"> </ScrollView> </LinearLayout>

.Java

@Override public View onCreateInputView() { LinearLayout myView = (LinearLayout) View.inflate(this, R.layout.my_layout, null); ScrollView scrollView = (ScrollView) myView.findViewById(R.id.keyboard_scroll); KeyboardView kv = (KeyboardView) getLayoutInflater().inflate(keyboard.xml, null); keyboard = new Keyboard(this, R.xml.qwerty); kv.setKeyboard(keyboard); kv.setOnKeyboardActionListener(this); scrollView.addView(kv); return myView; }