Android的自定义键盘:空格键的触摸面积不完全覆盖 [英] android custom keyboard: touch area of space key not completely covered

查看:514
本文介绍了Android的自定义键盘:空格键的触摸面积不完全覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个定制的Andr​​oid键盘,看起来几乎像原来的一个。它也有特殊的按键字母/数字和转移之间切换。所有键似乎除了空格键(在底部的大巴)完美地工作。我能够打空格键中间的不过倒是在右区和左(进近1/3空格键的宽度)不被识别为触摸。

我已经尝试过使用另一密钥code /图标空格键或甚至放置空格键在键盘的另一行,看看它是否是特定于键或行。但似乎有一种普遍的最大 - 宽度上的自定义键盘一键可以有......? I'ts也可再现的所有布局(肖像/风景/布局大...)。

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

 < XML版本=1.0编码=UTF-8&GT?;
<键盘的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
   机器人:keyWidth =35dp
    机器人:horizo​​ntalGap =3DP
    安卓的verticalGap =0.2%P
    机器人:keyHeight =9%P>

    <行的android:keyWidth =9%P>
        <关键的android:codeS =113机器人:keyLabel =Q机器人:keyEdgeFlags =左/>
        <关键的android:codeS =119机器人:keyLabel =W/>
        <关键的android:codeS =101机器人:keyLabel =E/>
        <关键的android:codeS =114机器人:keyLabel =R/>
        <关键的android:codeS =116机器人:keyLabel =T/>
        <关键的android:codeS =122机器人:keyLabel =Z/>
        <关键的android:codeS =117机器人:keyLabel =U/>
        <关键的android:codeS =105机器人:keyLabel =我/>
        <关键的android:codeS =111机器人:keyLabel =O/>
        <关键的android:codeS =112机器人:keyLabel =P/>

    < /行>

    <行的android:keyWidth =9%P>
        <关键的android:codeS =97机器人:keyLabel =一个机器人:horizo​​ntalGap =5%P
                机器人:keyEdgeFlags =左/>
        <关键的android:codeS =115机器人:keyLabel =S/>
        <关键的android:codeS =100机器人:keyLabel =D/>
        <关键的android:codeS =102机器人:keyLabel =F/>
        <关键的android:codeS =103机器人:keyLabel =G/>
        <关键的android:codeS =104机器人:keyLabel =H/>
        <关键的android:codeS =106机器人:keyLabel =J/>
        <关键的android:codeS =107机器人:keyLabel =K/>
        <关键的android:codeS =108机器人:keyLabel =L/>

    < /行>

    <行的android:keyWidth =9%P>
            <关键的android:isSticky =真正的机器人:codeS = -  2机器人:keyLabel =&放大器;#9650; />
        <关键的android:codeS =121机器人:keyLabel =Y/>
        <关键的android:codeS =120机器人:keyLabel =X/>
        <关键的android:codeS =99机器人:keyLabel =C/>
        <关键的android:codeS =118机器人:keyLabel =V/>
        <关键的android:codeS =98机器人:keyLabel =B/>
        <关键的android:codeS =110机器人:keyLabel =N/>
        <关键的android:codeS =109机器人:keyLabel =M/>

      <关键的android:codeS = -  5安卓keyIcon =@可绘制/ sym_keyboard_delete
                机器人:keyWidth =19%对机器人:keyEdgeFlags =右
                机器人:isRepeatable =真正的机器人:horizo​​ntalGap =1.5%P/>




    < /行>
    <行的android:horizo​​ntalGap =3DP
        安卓的verticalGap =3DP>

        !<  - <关键的android:codeS = -  1机器人:keyLabel =&放大器;#49;&安培;#50;&安培;#51;机器人:keyWidth =10%P/> - >
        <关键的android:codeS = -  1机器人:keyLabel =SYM机器人:keyWidth =10%P/>
         <关键的android:codeS =32机器人:keyIcon =@可绘制/ sym_keyboard_space
                机器人:keyWidth =68%对机器人:isRepeatable =真/>
            <关键的android:codeS = -  11机器人:isRepeatable =真正的机器人:keyIcon =@可绘制/ sym_keyboard_enter机器人:keyWidth =19%对机器人:keyEdgeFlags =右/>

    < /行>

< /键盘>
 

解决方案

这个问题似乎是,从键盘#getNearestKeys方法dosent宽按钮返回正确的价值观。 我通过扩展键盘类并覆盖getNearestKeys方法解决了这个问题。

这是在code我说:

  @覆盖
公众诠释[] getNearestKeys(INT X,int y)对{
    名单<关键>键= getKeys();
    键[] mKeys = keys.toArray(新的关键[keys.size());
    INT I = 0;
    针对(主要关键:mKeys){
        如果(key.isInside(X,Y))
            返回新INT [] {I};
        我++;
    }
    返回新INT [0];
}
 

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 ...).

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>

解决方案

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

this is the code I added:

@Override
public int[] getNearestKeys(int x, int y) {
    List<Key> keys = getKeys();
    Key[] mKeys = keys.toArray(new Key[keys.size()]);
    int i = 0;
    for (Key key : mKeys) {
        if(key.isInside(x, y))
            return new int[]{i};
        i++;
    }
    return new int[0];
}

这篇关于Android的自定义键盘:空格键的触摸面积不完全覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆