android自定义键盘:空格键的触摸区域未完全覆盖

android custom keyboard: touch area of space key not completely covered(android自定义键盘:空格键的触摸区域未完全覆盖)
本文介绍了android自定义键盘:空格键的触摸区域未完全覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我开发了一个 android 自定义键盘,它看起来几乎就像原来的键盘之一.它还有特殊的键可以在字母/数字和班次之间切换.除了SPACE"键(底部的大条)之外,所有键似乎都可以正常工作.我可以按中间的空格键但触摸左右区域(大约是空格键宽度的 1/3)不被识别为触摸.

I have developed an android custom keyboard which looks almost like one of the original ones. It has also special keys to switch between letters / numbers and shift. all keys seem to work perfectly except the "SPACE" key (the large bar at the bottom). I am able to hit the space bar in the middle but touches on areas on the right and left (appr. 1/3 of the width of the space bar) are not recognized as touches.

我已经尝试为空格键使用另一个键码/图标,甚至将空格键放在键盘的另一行,以查看它是否特定于该键或行.但似乎自定义键盘上的键可以具有一般的最大"宽度......?我也可以在所有布局中重现(纵向/横向/布局-大...).

I already tried to use another keycode / icon for the space bar or even place the spacebar in another row of the keyboard to see if it is specific to that key or row. But it seems there is a general "maximum"-width a key on a custom keyboards can have...? I'ts also reproducable in all layouts (portrait / landscape / layout-large ...).

下面是我的 keypad.xml 文件来定义我的键盘.有谁知道这个问题/限制?

Below is my keypad.xml file to define my keyboard. Does anyone know about this issue / limitation?

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
   android:keyWidth="35dp"
    android:horizontalGap="3dp"
    android:verticalGap="0.2%p"
    android:keyHeight="9%p">

    <Row  android:keyWidth="9%p" >
        <Key android:codes="113" android:keyLabel="q" android:keyEdgeFlags="left"/>
        <Key android:codes="119" android:keyLabel="w"/>
        <Key android:codes="101" android:keyLabel="e"/>
        <Key android:codes="114" android:keyLabel="r"/>
        <Key android:codes="116" android:keyLabel="t"/>
        <Key android:codes="122" android:keyLabel="z"/>
        <Key android:codes="117" android:keyLabel="u"/>
        <Key android:codes="105" android:keyLabel="i"/>
        <Key android:codes="111" android:keyLabel="o"/>
        <Key android:codes="112" android:keyLabel="p" />

    </Row>

    <Row android:keyWidth="9%p"   >
        <Key android:codes="97" android:keyLabel="a" android:horizontalGap="5%p" 
                android:keyEdgeFlags="left"/>
        <Key android:codes="115" android:keyLabel="s"/>
        <Key android:codes="100" android:keyLabel="d"/>
        <Key android:codes="102" android:keyLabel="f"/>
        <Key android:codes="103" android:keyLabel="g"/>
        <Key android:codes="104" android:keyLabel="h"/>
        <Key android:codes="106" android:keyLabel="j"/>
        <Key android:codes="107" android:keyLabel="k"/>
        <Key android:codes="108" android:keyLabel="l"/>

    </Row>

    <Row android:keyWidth="9%p" >
            <Key android:isSticky="true" android:codes="-2" android:keyLabel="&#9650;" />
        <Key android:codes="121" android:keyLabel="y"/>
        <Key android:codes="120" android:keyLabel="x"/>
        <Key android:codes="99" android:keyLabel="c"/>
        <Key android:codes="118" android:keyLabel="v"/>
        <Key android:codes="98" android:keyLabel="b"/>
        <Key android:codes="110" android:keyLabel="n"/>
        <Key android:codes="109" android:keyLabel="m"/>

      <Key  android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete" 
                android:keyWidth="19%p" android:keyEdgeFlags="right"
                android:isRepeatable="true" android:horizontalGap="1.5%p"/>




    </Row>
    <Row android:horizontalGap="3dp"
        android:verticalGap="3dp">

        <!-- <Key android:codes="-1" android:keyLabel="&#49;&#50;&#51;" android:keyWidth="10%p"/> -->
        <Key android:codes="-1" android:keyLabel="SYM" android:keyWidth="10%p"/>
         <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
                android:keyWidth="68%p" android:isRepeatable="true"/>
            <Key android:codes="-11"  android:isRepeatable="true" android:keyIcon="@drawable/sym_keyboard_enter" android:keyWidth="19%p" android:keyEdgeFlags="right"/>

    </Row>

</Keyboard>

推荐答案

问题似乎是来自 Keyboard#getNearestKeys 的方法为宽按钮返回了正确的值.我通过扩展 Keyboard 类并覆盖 getNearestKeys 方法解决了这个问题

The problem seems to be that the method from Keyboard#getNearestKeys dosent return proper values for wide buttons. I solved the problem by extending the Keyboard class and overriding the getNearestKeys method

这是我添加的代码:

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

这篇关于android自定义键盘:空格键的触摸区域未完全覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Android Mocking a Dagger2 injected dependency for a Espresso test(Android 为 Espresso 测试模拟 Dagger2 注入依赖项)
Mock object in Android Unit test with kotlin - any() gives null(使用 kotlin 在 Android 单元测试中模拟对象 - any() 给出 null)
How to mock Context using Mockito?(如何使用 Mockito 模拟上下文?)
Unit test Android, getString from resource(单元测试Android,从资源中获取字符串)
Mockito - what does verify method do?(Mockito - 验证方法有什么作用?)
Unit Testing in Retrofit for Callback(回调改造中的单元测试)