Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android soft keyboard keys center gravity

I have been working on a custom keyboard but i am facing a problem that i can not figure how to solve. I am trying to aling all keys of every row in the center. I mean that even if a row has 9 or 10 or 11 keys all are alligned at center. This is what my keyboard looks like now:

http://postimg.org/image/6jy1uyd6x/

What am I doing wrong? Here is my xml file too:

    <?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:horizontalGap="1%p"
    android:verticalGap="0.4%p"
    >
    <Row android:keyWidth="9%p" android:keyHeight="75dip" android:rowEdgeFlags="top">
        <Key android:codes="49" android:keyLabel=";" android:keyEdgeFlags="left"/>
        <Key android:codes="50" android:keyLabel="ς"/>
        <Key android:codes="51" android:keyLabel="ε"/>
        <Key android:codes="52" android:keyLabel="ρ"/>
        <Key android:codes="53" android:keyLabel="τ"/>
        <Key android:codes="54" android:keyLabel="υ"/>
        <Key android:codes="55" android:keyLabel="θ"/>
        <Key android:codes="56" android:keyLabel="ι"/>
        <Key android:codes="57" android:keyLabel="ο"/>
        <Key android:codes="48" android:keyLabel="π" android:keyEdgeFlags="right"/>
    </Row>

This is my keyboard.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/keyboard"
    android:imeOptions="flagNoFullscreen"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center|fill_horizontal"
    android:layout_alignParentBottom="true"
    android:keyPreviewLayout ="@layout/preview"
    android:keyBackground="@drawable/key_background"
    android:keyTextSize="35sp"
    android:keyTextColor="@color/key_text_color"
    android:keyPreviewHeight="50sp"
    android:shadowRadius="1"
    android:shadowColor="#fff"
    android:padding="0px" android:layout_margin="0px"
    tools:ignore="ResAuto" />

I dont want to use %p cause its not the best way to make this out. Thank you in advance!

like image 507
George Avatar asked Sep 29 '22 14:09

George


2 Answers

try setting the first key android:keyEdgeFlags="left" and add android:horizontalGap="5%p" to it

<Row    >
        <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" android:keyEdgeFlags="right"/>
    </Row>
like image 127
Zar E Ahmer Avatar answered Oct 05 '22 06:10

Zar E Ahmer


I've found a solution that worked for me.

What Nepster suggested to you was right, except that I removed the keyEdgeFlags="right" form the last letter.

<Row>
<key android:label="a" codes.... android:keyEdgeFlags="left" android:horizontalGap="5%p"/>
<key "s" .../>
<key "d" .../>
....
<key android:label="l" codes ... />

This is giving me this layout:

this is only one of my example just compiled

like image 39
pippo Avatar answered Oct 05 '22 06:10

pippo