自定义键盘布局不适合屏幕
Custom keyboard layout not fits on screen
我得到了一个为玩基于文本的游戏而设计的自定义键盘。问题是当我把 verticalGap
和 horizontalGap
放在一个小的键间隙时,键不适合。键不适合屏幕的原因是,我有一个高度为 3 行的键(主键)。所以我为我的主键(宽度为 40%p)制作了第 2 行和第 3 行键 40%p
。我的键盘 xml 键是:res/xml/drpgkeys.xml
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="5dp"
android:keyHeight="9%p"
android:keyWidth="10%p"
android:verticalGap="5dp">
<Row>
<Key
android:codes="888"
android:keyEdgeFlags="left"
android:keyHeight="27%p"
android:keyLabel="ADV"
android:keyWidth="40%p" />
<Key
android:codes="907"
android:keyLabel="MINE"
android:keyWidth="30%p" />
<Key
android:codes="905"
android:keyEdgeFlags="right"
android:keyLabel="CHOP"
android:keyWidth="30%p" />
</Row>
<Row>
<Key
android:codes="906"
android:horizontalGap="40%p"
android:keyLabel="FORAGE"
android:keyWidth="30%p" />
<Key
android:codes="908"
android:keyEdgeFlags="right"
android:keyLabel="FISH"
android:keyWidth="30%p" />
</Row>
<Row android:keyHeight="8%p">
<Key
android:codes="201"
android:horizontalGap="40%p"
android:keyLabel="O.o"
android:keyWidth="12%p"
android:popupKeyboard="@xml/inv" />
<Key
android:codes="334"
android:keyLabel="Undefined"
android:keyWidth="36%p"
android:popupKeyboard="@xml/market" />
<Key
android:codes="202"
android:keyEdgeFlags="right"
android:keyLabel="o.O"
android:keyWidth="12%p"
android:popupKeyboard="@xml/ginv" />
</Row>
<Row
android:keyHeight="8%p"
android:rowEdgeFlags="bottom">
<Key
android:codes="900"
android:keyEdgeFlags="left"
android:keyLabel="STATS"
android:keyWidth="20%p"
android:popupKeyboard="@xml/stats" />
<Key
android:codes="901"
android:keyLabel="PET"
android:keyWidth="20%p" />
<Key
android:codes="903"
android:keyLabel="HEAL"
android:keyWidth="20%p" />
<Key
android:codes="904"
android:keyLabel="PHEAL"
android:keyWidth="20%p" />
<Key
android:codes="333"
android:keyEdgeFlags="right"
android:keyIcon="@drawable/key_icon"
android:keyWidth="20%p"
android:popupKeyboard="@xml/optionkey" />
</Row>
</Keyboard>
我的键盘布局是:res/layout/keyboard.xml
<?xml version="1.0" encoding="UTF-8"?>
<drpg.ddkeys.ddKeysView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true"
android:keyBackground="@drawable/key_background"
android:keyPreviewLayout="@null"
android:keyTextColor="#99b3c4"
android:popupLayout="@layout/popupkeys" />
我的key_backgroud drawable
正常状态键盘是https://pastebin.com/raw/hTLJ8PZu
键盘照片:https://i.imgur.com/Sf6DVad.jpg
其中,ADV
键的高度小于第 3 行键,第 2 行和第 3 行在屏幕外。
我已通过从 Keyboard 级别删除 android:horizontalGap
并将其应用于 Key 级别来解决我的问题。并在 %p 中设置 horizontalGap 并调整每个键的大小,这样我的总键宽应该达到 100%p。
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyHeight="9%p"
android:keyWidth="10%p"
android:verticalGap="0.55%p">
<Row>
<Key
android:codes="888"
android:keyEdgeFlags="left"
android:keyHeight="27%p"
android:keyLabel="ADV"
android:keyWidth="40%p" />
<Key
android:codes="907"
android:horizontalGap="1%p"
android:keyLabel="MINE"
android:keyWidth="29%p" />
<Key
android:codes="905"
android:horizontalGap="1%p"
android:keyEdgeFlags="right"
android:keyLabel="CHOP"
android:keyWidth="29%p" />
</Row>
<Row>
<Key
android:codes="906"
android:horizontalGap="41%p"
android:keyLabel="FORAGE"
android:keyWidth="29%p" />
<Key
android:codes="908"
android:horizontalGap="1%p"
android:keyEdgeFlags="right"
android:keyLabel="FISH"
android:keyWidth="29%p" />
</Row>
<Row
android:keyHeight="8%p"
android:keyboardMode="@integer/default_keys">
<Key
android:codes="201"
android:horizontalGap="41%p"
android:keyLabel="O.o"
android:keyWidth="11%p"
android:popupKeyboard="@xml/inv" />
<Key
android:codes="334"
android:horizontalGap="1%p"
android:keyLabel="Undefined"
android:keyWidth="35%p"
android:popupKeyboard="@xml/market" />
<Key
android:codes="202"
android:horizontalGap="1%p"
android:keyEdgeFlags="right"
android:keyLabel="o.O"
android:keyWidth="11%p"
android:popupKeyboard="@xml/ginv" />
</Row>
<Row
android:keyHeight="8%p"
android:keyboardMode="@integer/custom_keys">
<Key
android:codes="201"
android:horizontalGap="41%p"
android:keyLabel="O_o"
android:keyWidth="11%p"
android:popupKeyboard="@xml/customkeys_left" />
<Key
android:codes="334"
android:horizontalGap="1%p"
android:keyLabel="Undefined"
android:keyWidth="35%p"
android:popupKeyboard="@xml/market" />
<Key
android:codes="202"
android:horizontalGap="1%p"
android:keyEdgeFlags="right"
android:keyLabel="o_O"
android:keyWidth="11%p"
android:popupKeyboard="@xml/customkeys_right" />
</Row>
<Row
android:keyHeight="8%p"
android:rowEdgeFlags="bottom">
<Key
android:codes="900"
android:keyEdgeFlags="left"
android:keyLabel="STATS"
android:keyWidth="19.2%p"
android:popupKeyboard="@xml/stats" />
<Key
android:codes="901"
android:keyLabel="PET"
android:keyWidth="19.2%p"
android:horizontalGap="1%p"/>
<Key
android:codes="903"
android:keyLabel="HEAL"
android:keyWidth="19.2%p"
android:horizontalGap="1%p" />
<Key
android:codes="904"
android:keyLabel="PHEAL"
android:keyWidth="19.2%p"
android:horizontalGap="1%p" />
<Key
android:codes="333"
android:keyEdgeFlags="right"
android:keyIcon="@drawable/key_icon"
android:keyWidth="19.2%p"
android:popupKeyboard="@xml/optionkey"
android:horizontalGap="1%p"/>
</Row>
</Keyboard>
我得到了一个为玩基于文本的游戏而设计的自定义键盘。问题是当我把 verticalGap
和 horizontalGap
放在一个小的键间隙时,键不适合。键不适合屏幕的原因是,我有一个高度为 3 行的键(主键)。所以我为我的主键(宽度为 40%p)制作了第 2 行和第 3 行键 40%p
。我的键盘 xml 键是:res/xml/drpgkeys.xml
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="5dp"
android:keyHeight="9%p"
android:keyWidth="10%p"
android:verticalGap="5dp">
<Row>
<Key
android:codes="888"
android:keyEdgeFlags="left"
android:keyHeight="27%p"
android:keyLabel="ADV"
android:keyWidth="40%p" />
<Key
android:codes="907"
android:keyLabel="MINE"
android:keyWidth="30%p" />
<Key
android:codes="905"
android:keyEdgeFlags="right"
android:keyLabel="CHOP"
android:keyWidth="30%p" />
</Row>
<Row>
<Key
android:codes="906"
android:horizontalGap="40%p"
android:keyLabel="FORAGE"
android:keyWidth="30%p" />
<Key
android:codes="908"
android:keyEdgeFlags="right"
android:keyLabel="FISH"
android:keyWidth="30%p" />
</Row>
<Row android:keyHeight="8%p">
<Key
android:codes="201"
android:horizontalGap="40%p"
android:keyLabel="O.o"
android:keyWidth="12%p"
android:popupKeyboard="@xml/inv" />
<Key
android:codes="334"
android:keyLabel="Undefined"
android:keyWidth="36%p"
android:popupKeyboard="@xml/market" />
<Key
android:codes="202"
android:keyEdgeFlags="right"
android:keyLabel="o.O"
android:keyWidth="12%p"
android:popupKeyboard="@xml/ginv" />
</Row>
<Row
android:keyHeight="8%p"
android:rowEdgeFlags="bottom">
<Key
android:codes="900"
android:keyEdgeFlags="left"
android:keyLabel="STATS"
android:keyWidth="20%p"
android:popupKeyboard="@xml/stats" />
<Key
android:codes="901"
android:keyLabel="PET"
android:keyWidth="20%p" />
<Key
android:codes="903"
android:keyLabel="HEAL"
android:keyWidth="20%p" />
<Key
android:codes="904"
android:keyLabel="PHEAL"
android:keyWidth="20%p" />
<Key
android:codes="333"
android:keyEdgeFlags="right"
android:keyIcon="@drawable/key_icon"
android:keyWidth="20%p"
android:popupKeyboard="@xml/optionkey" />
</Row>
</Keyboard>
我的键盘布局是:res/layout/keyboard.xml
<?xml version="1.0" encoding="UTF-8"?>
<drpg.ddkeys.ddKeysView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true"
android:keyBackground="@drawable/key_background"
android:keyPreviewLayout="@null"
android:keyTextColor="#99b3c4"
android:popupLayout="@layout/popupkeys" />
我的key_backgroud drawable
正常状态键盘是https://pastebin.com/raw/hTLJ8PZu
键盘照片:https://i.imgur.com/Sf6DVad.jpg
其中,ADV
键的高度小于第 3 行键,第 2 行和第 3 行在屏幕外。
我已通过从 Keyboard 级别删除 android:horizontalGap
并将其应用于 Key 级别来解决我的问题。并在 %p 中设置 horizontalGap 并调整每个键的大小,这样我的总键宽应该达到 100%p。
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyHeight="9%p"
android:keyWidth="10%p"
android:verticalGap="0.55%p">
<Row>
<Key
android:codes="888"
android:keyEdgeFlags="left"
android:keyHeight="27%p"
android:keyLabel="ADV"
android:keyWidth="40%p" />
<Key
android:codes="907"
android:horizontalGap="1%p"
android:keyLabel="MINE"
android:keyWidth="29%p" />
<Key
android:codes="905"
android:horizontalGap="1%p"
android:keyEdgeFlags="right"
android:keyLabel="CHOP"
android:keyWidth="29%p" />
</Row>
<Row>
<Key
android:codes="906"
android:horizontalGap="41%p"
android:keyLabel="FORAGE"
android:keyWidth="29%p" />
<Key
android:codes="908"
android:horizontalGap="1%p"
android:keyEdgeFlags="right"
android:keyLabel="FISH"
android:keyWidth="29%p" />
</Row>
<Row
android:keyHeight="8%p"
android:keyboardMode="@integer/default_keys">
<Key
android:codes="201"
android:horizontalGap="41%p"
android:keyLabel="O.o"
android:keyWidth="11%p"
android:popupKeyboard="@xml/inv" />
<Key
android:codes="334"
android:horizontalGap="1%p"
android:keyLabel="Undefined"
android:keyWidth="35%p"
android:popupKeyboard="@xml/market" />
<Key
android:codes="202"
android:horizontalGap="1%p"
android:keyEdgeFlags="right"
android:keyLabel="o.O"
android:keyWidth="11%p"
android:popupKeyboard="@xml/ginv" />
</Row>
<Row
android:keyHeight="8%p"
android:keyboardMode="@integer/custom_keys">
<Key
android:codes="201"
android:horizontalGap="41%p"
android:keyLabel="O_o"
android:keyWidth="11%p"
android:popupKeyboard="@xml/customkeys_left" />
<Key
android:codes="334"
android:horizontalGap="1%p"
android:keyLabel="Undefined"
android:keyWidth="35%p"
android:popupKeyboard="@xml/market" />
<Key
android:codes="202"
android:horizontalGap="1%p"
android:keyEdgeFlags="right"
android:keyLabel="o_O"
android:keyWidth="11%p"
android:popupKeyboard="@xml/customkeys_right" />
</Row>
<Row
android:keyHeight="8%p"
android:rowEdgeFlags="bottom">
<Key
android:codes="900"
android:keyEdgeFlags="left"
android:keyLabel="STATS"
android:keyWidth="19.2%p"
android:popupKeyboard="@xml/stats" />
<Key
android:codes="901"
android:keyLabel="PET"
android:keyWidth="19.2%p"
android:horizontalGap="1%p"/>
<Key
android:codes="903"
android:keyLabel="HEAL"
android:keyWidth="19.2%p"
android:horizontalGap="1%p" />
<Key
android:codes="904"
android:keyLabel="PHEAL"
android:keyWidth="19.2%p"
android:horizontalGap="1%p" />
<Key
android:codes="333"
android:keyEdgeFlags="right"
android:keyIcon="@drawable/key_icon"
android:keyWidth="19.2%p"
android:popupKeyboard="@xml/optionkey"
android:horizontalGap="1%p"/>
</Row>
</Keyboard>