Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

i am developing a keyboard but when i put android:keyWidth="40%p" more than 40. right side of the space key is not clickble.

i use android studio. and custom keyboardview with xml like this

full code is

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

The problem is related to a method from Keyboard#getNearestKeys that doesn't return proper values for wide buttons. You can solve the problem by extending the Keyboard class and overriding the getNearestKeys method.

like this

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

Copied from here

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.