我正在开发一个键盘,但是当我把android:keyWidth=" 40 %p“放在40以上的时候。不能单击空格键的右侧。
我使用的是android studio。和自定义的keyboardview,如下所示
完整的代码是
<Keyboard ><Row android:rowEdgeFlags="bottom">
<Key android:keyWidth="10%" android:codes="-2" android:keyLabel="43" android:keyEdgeFlags="left" />
<Key android:keyWidth="10%" android:codes="-6" android:keyLabel="f" />
<Key android:keyWidth="10%p" android:codes="44" android:isRepeatable="true" android:keyLabel=","/>
<Key android:keyWidth="45%p" android:codes="32" android:isRepeatable="true" android:keyLabel="space"/>
<Key android:keyWidth="10%p" android:codes="46" android:isRepeatable="true" android:keyLabel="." />
<Key android:keyWidth="13%p" android:keyEdgeFlags="right" android:codes="10" android:keyLabel="enter" />
</Row>
这个输出但是android:keyWidth="45%p“只有40%的空格键是可点击的。
发布于 2020-11-01 20:56:30
这个问题与Keyboard#getNearestKeys的一个方法有关,该方法没有为宽按钮返回正确的值。您可以通过扩展Keyboard类并重写getNearestKeys方法来解决此问题。
像这样
public class CustomKeyboard extends Keyboard {
public CustomKeyboard(Context context, int xmlLayoutResId) {
super(context, xmlLayoutResId);
}
@Override
public int[] getNearestKeys(int x, int y) {
List<Key> keys = getKeys();
for (int i = 0; i < keys.size(); i++) {
if (keys.get(i).isInside(x, y)) return new int[]{i};
}
return new int[0];
} }从here复制
https://stackoverflow.com/questions/55546926
复制相似问题