1

Я пытаюсь создать собственный макет клавиатуры, который имеет 3 клавиши влево, пробел, 3 клавиши посередине, пробел и один ключ. Показанное на плюсах, ряд на клавиатуре должен выглядеть следующим образом:Применение KeyboardView в android

+++ = +++ = +

где знак плюс ключи и = представляет пробела. Мой XML-код:

<?xml version="1.0" encoding="utf-8"?> 
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
android:keyWidth="12.50%p" 
android:keyHeight="8.9%p"> 


<Row> 
    <Key android:codes="1"  android:keyLabel="sin"       android:isRepeatable="true" android:keyEdgeFlags="left" /> 
    <Key android:codes="2"  android:keyLabel="cos"      android:isRepeatable="true" /> 
    <Key android:codes="3"  android:keyLabel="tan"      android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="-1"  android:keyLabel="DRAW"      android:isRepeatable="true" android:keyWidth="25%p"  /> 
    <Key android:codes="22"  android:keyLabel="x\u207F"     android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="-2"  android:keyIcon="@drawable/delete_symbol" android:isRepeatable="true" android:keyEdgeFlags="right"/> 
</Row> 
<Row> 
    <Key android:codes="4"  android:keyLabel="asin"  android:isRepeatable="true"  android:keyEdgeFlags="left" /> 
    <Key android:codes="5"  android:keyLabel="acos"  android:isRepeatable="true" /> 
    <Key android:codes="6"  android:keyLabel="atan"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="36"  android:keyLabel="sinh"  android:isRepeatable="true" /> 
    <Key android:codes="37"  android:keyLabel="cosh"  android:isRepeatable="true" /> 
    <Key android:codes="38"  android:keyLabel="tanh"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="21"  android:keyLabel="\u00F7" android:isRepeatable="true" android:keyEdgeFlags="right" /> 
</Row> 
<Row> 
    <Key android:codes="42"  android:keyLabel="asinh" android:isRepeatable="true"  android:keyEdgeFlags="left" /> 
    <Key android:codes="43"  android:keyLabel="acosh"  android:isRepeatable="true" /> 
    <Key android:codes="44"  android:keyLabel="atanh"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="33"  android:keyLabel="7"  android:isRepeatable="true"  /> 
    <Key android:codes="34"  android:keyLabel="8"  android:isRepeatable="true" /> 
    <Key android:codes="35"  android:keyLabel="9"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p"/> 
    <Key android:codes="20"  android:keyLabel="\u00D7" android:isRepeatable="true" android:keyEdgeFlags="right" /> 
</Row> 

<Row> 
    <Key android:codes="10"  android:keyLabel="\u221a" android:keyEdgeFlags="left"  android:isRepeatable="true" /> 
    <Key android:codes="11"  android:keyLabel="e^("  android:isRepeatable="true" /> 
    <Key android:codes="12"  android:keyLabel="ln("  android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="30"  android:keyLabel="4"  android:isRepeatable="true"  /> 
    <Key android:codes="31"  android:keyLabel="5"  android:isRepeatable="true" /> 
    <Key android:codes="32"  android:keyLabel="6"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="19"  android:keyLabel="\u2212"  android:isRepeatable="true"  android:keyEdgeFlags="right" /> 
</Row> 

<Row> 
    <Key android:codes="40"  android:keyLabel="log"  android:isRepeatable="true"  android:keyEdgeFlags="left" /> 
    <Key android:codes="41"  android:keyLabel="abs" android:isRepeatable="true" /> 
    <Key android:codes="13"  android:keyIcon="@drawable/italic_x"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p"/> 
    <Key android:codes="27"  android:keyLabel="1"  android:isRepeatable="true"  /> 
    <Key android:codes="28"  android:keyLabel="2"  android:isRepeatable="true" /> 
    <Key android:codes="29"  android:keyLabel="3"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p"/> 
    <Key android:codes="18"  android:keyLabel="+"  android:isRepeatable="true"  android:keyEdgeFlags="right" /> 
</Row> 

<Row> 
    <Key android:codes="-3"  android:keyIcon="@drawable/keyboard_done"  android:isRepeatable="true"  android:keyWidth="25%p"   android:keyEdgeFlags="left" /> 
    <Key android:codes="19"  android:keyLabel="(-)"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="16"  android:keyLabel="("  android:isRepeatable="true"  /> 
    <Key android:codes="26"  android:keyLabel="0"  android:isRepeatable="true" /> 
    <Key android:codes="17"  android:keyLabel=")"  android:isRepeatable="true" 
     android:horizontalGap="6.25%p" /> 
    <Key android:codes="23"  android:keyLabel="."  android:isRepeatable="true"  android:keyEdgeFlags="right" /> 
</Row> 

на Android 4.4; в частности Samsung Galaxy s4 и s5, пользовательская клавиатура выглядит красиво. На Samsung Galaxy S3 и остальных устройств с размером экрана менее 5inches, клавиатура искажается и выглядит следующим образом:

++ = ++++++

Смысл моего XML-кода для пользовательских клавиатура выглядит следующим образом: - у меня есть 7 клавиш подряд - каждая клавиша занимает 12,5% ширины экрана (в общей сложности 87,5% для 7 клавиш) - каждый из 2 основных пространств (= знак в моем рисунок) занимают 6,25% ширины экрана. - выше общая ширина экрана 100%

Итак, согласно моим рассуждениям, файл xml, который я опубликовал, должен работать на всех устройствах. Но этого не происходит.

Поскольку я искал решение в Google, я получил некоторую информацию о том, что в клавиатуре есть ошибка. Ошибка была описана как:

NOTE When we add a horizontalGap in pixels, this interferes with keyWidth in percentages adding up to 100% 
NOTE When we have a horizontalGap (on Keyboard level) of 0, this make the horizontalGap (on Key level) to move from after the key to before the key... (I consider this a bug) 

Может кто-то пожалуйста, помогите

ответ

1

Да, это ошибка в Android, но, к счастью, есть обходной путь.

Решение состоит в том, чтобы добавить пустую клавишу с horizontalGap> 0 и width = 0 между клавишами, где вам нужно пустое пространство. Эта пустая клавиша будет единственной с горизонтальнымGap; все остальные ключи не должны иметь этот атрибут.

Вот мой собственный пример из трех видимых ключей с промежутками между ними:

<Row> 
    <Key android:codes="1" android:keyLabel="First key" android:keyEdgeFlags="left" /> 
    <Key android:codes="-999" android:keyLabel="" android:keyWidth="0%p" android:horizontalGap="2.0%p" /> 
    <Key android:codes="2" android:keyLabel="Second key" /> 
    <Key android:codes="-999" android:keyLabel="" android:keyWidth="0%p" android:horizontalGap="2.0%p" /> 
    <Key android:codes="3" android:keyLabel="Third key" android:keyEdgeFlags="right"/> 
</Row>