gpt4 book ai didi

android - 在android中应用KeyboardView

转载 作者:行者123 更新时间:2023-11-29 00:15:26 26 4
gpt4 key购买 nike

我正在尝试制作一个自定义键盘布局,左侧有 3 个键,一个空格,中间有 3 个键,一个空格和一个键。由加号显示,键盘上的一行应如下所示:

+++=+++=+

其中加号是键,= 代表空格。我的 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>

在安卓 4.4 上;特别是 Samsung Galaxy s4 和 s5,自定义键盘看起来很漂亮。在 Samsung galaxy s3 和其他屏幕尺寸小于 5 英寸的设备上,键盘变形,看起来像:

++=++++++

自定义键盘布局的 xml 代码背后的原因是:- 我连续有 7 个键- 每个键占屏幕宽度的 12.5%(7 个键总共占 87.5%)- 2 个主要空间(= 在我的插图中签名)各占屏幕宽度的 6.25%。- 以上合计为 100% 屏幕宽度

所以根据我的推理,我发布的 xml 文件应该适用于所有设备。但这并没有发生。

当我在 Google 上搜索解决方案时,我通过一些信息得知键盘 View 中存在错误。该错误被描述为:

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)

谁能帮忙

最佳答案

是的,这是 Android 中的一个错误,但幸运的是有一个解决方法。

解决方案是在需要空白的键之间添加一个 horizo​​ntalGap > 0 和 width = 0 的空键。这个空键将是唯一一个有 horizo​​ntalGap 的键;所有其他键不应该有这个属性。

这是我自己的三个可见键的示例,它们之间有空格:

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

关于android - 在android中应用KeyboardView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27258381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com