如何向 Android 中的 KeyboardView 添加填充?
How to add a padding to a KeyboardView in Android?
我有一排钥匙。每个键的宽度为 18.5%,间隙为 2%。但是,我希望右侧第一个键的间隙为 10%,最后一个键的间隙为 10%。在每个键上设置 horizontalGap 来实现这种效果很简单,除了我看不到设置右侧间隙的方法。
我想要的间距如下(括号内为键,否则为空隙):
10% [18.5%] 2% [18.5%] 2% [18.5%] 2% [18.5%] 10%
我试过:
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="18.5%p"
android:horizontalGap="2%"
android:keyHeight="7%p">
<Row>
<Key android:codes="1" android:keyLabel="1" android:horizontalGap="10%p" />
<Key android:codes="2" android:keyLabel="2" />
<Key android:codes="3" android:keyLabel="3" />
<Key android:codes="4" android:keyLabel="4" />
</Row>
</Keyboard>
尽管 KeyboardView 宽度设置为 fill_parent,但这并没有给我 10% 的差距。为什么我的键盘在连续的键之后有10%的差距?
将宽度设置为 wrap_content 并在其父项内水平居中。
我有一排钥匙。每个键的宽度为 18.5%,间隙为 2%。但是,我希望右侧第一个键的间隙为 10%,最后一个键的间隙为 10%。在每个键上设置 horizontalGap 来实现这种效果很简单,除了我看不到设置右侧间隙的方法。
我想要的间距如下(括号内为键,否则为空隙):
10% [18.5%] 2% [18.5%] 2% [18.5%] 2% [18.5%] 10%
我试过:
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="18.5%p"
android:horizontalGap="2%"
android:keyHeight="7%p">
<Row>
<Key android:codes="1" android:keyLabel="1" android:horizontalGap="10%p" />
<Key android:codes="2" android:keyLabel="2" />
<Key android:codes="3" android:keyLabel="3" />
<Key android:codes="4" android:keyLabel="4" />
</Row>
</Keyboard>
尽管 KeyboardView 宽度设置为 fill_parent,但这并没有给我 10% 的差距。为什么我的键盘在连续的键之后有10%的差距?
将宽度设置为 wrap_content 并在其父项内水平居中。