title: Android custom keyboard layout leaving a margin of white at the side
body: <p>I'm working on a custom keyboard for Android, and I've run in to an issue where the keyboard seems to leave a white line/space at right, instead of filling the parent view... (don't mind the icons, it's simply placeholder graphic for now)</p>
  
  <p><a href="https://i.stack.imgur.com/1TlhT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1TlhT.png" alt="Screenshot from the simulator"></a></p>
  
  <p>Below you can see my layout...</p>
  
  <pre><code>&lt;Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
      android:keyWidth="14%p"
      android:horizontalGap="0px"
      android:verticalGap="0px"
      android:keyHeight="60dp"
      &gt;
      &lt;Row&gt;
          &lt;Key android:codes="49" android:keyIcon="@drawable/rsz_emoji" android:horizontalGap="1%p" android:keyEdgeFlags="left"/&gt;
          &lt;Key android:codes="50" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="51" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="52" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="53" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="54" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="48" android:keyIcon="@drawable/rsz_emoji" android:keyEdgeFlags="right"/&gt;
      &lt;/Row&gt;
      &lt;Row&gt;
          &lt;Key android:codes="113" android:keyIcon="@drawable/rsz_emoji" android:horizontalGap="8%p" android:keyEdgeFlags="left"/&gt;
          &lt;Key android:codes="114" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="116" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="121" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="111" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="112" android:keyIcon="@drawable/rsz_emoji" android:keyEdgeFlags="right"/&gt;
      &lt;/Row&gt;
      &lt;Row&gt;
          &lt;Key android:codes="1" android:keyIcon="@drawable/rsz_emoji" android:keyWidth="28%p" android:horizontalGap="8%p" android:keyEdgeFlags="left"/&gt;
          &lt;Key android:codes="46" android:keyIcon="@drawable/rsz_emoji" android:keyWidth="28%p"/&gt;
          &lt;Key android:codes="58" android:keyIcon="@drawable/rsz_emoji" android:keyWidth="28%p" android:keyEdgeFlags="right"/&gt;
      &lt;/Row&gt;
      &lt;Row android:rowEdgeFlags="bottom"&gt;
          &lt;Key android:codes="44" android:keyIcon="@drawable/globe" android:horizontalGap="8%p" android:keyEdgeFlags="left"/&gt;
          &lt;Key android:codes="47" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="32" android:keyIcon="@drawable/rsz_emoji" android:keyWidth="28%p"/&gt;
          &lt;Key android:codes="1" android:keyIcon="@drawable/rsz_emoji"/&gt;
          &lt;Key android:codes="-5" android:keyIcon="@drawable/backspace" android:keyEdgeFlags="right"/&gt;
      &lt;/Row&gt;
  &lt;/Keyboard&gt;
  </code></pre>
  
  <p>As far as I can see, it's a matter of <code>1%p</code>... But I'm a bit unsure how to fill it without messing up my alignments... E.g. changing the gap in the first row to 2 would fix it, but mess up the alignment.</p>
  
  <p>Added extra code for you as requested...</p>
  
  <p>My class extending <code>InputMethodService</code>:</p>
  
  <pre><code>    private KeyboardView kv;
      private Keyboard keyboard;
  
      @Override
      public View onCreateInputView() {
          kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
          keyboard = new Keyboard(this, R.xml.custom_keyboard);
          kv.setPreviewEnabled(false);
          kv.setKeyboard(keyboard);
          kv.setOnKeyboardActionListener(this);
          return kv;
      }
  
      @Override
      public void onPress(int primaryCode) {
  
      }
  
      @Override
      public void onRelease(int primaryCode) {
  
      }
  
      @Override
      public void onKey(int primaryCode, int[] keyCodes) {
          InputConnection ic = getCurrentInputConnection();
  
          if (primaryCode == Keyboard.KEYCODE_DELETE) {
              ic.deleteSurroundingText(1, 0);
          } else {
              Drawable mDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.rsz_emoji, null);
              Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
              String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Emoticon", null);
              Uri fileUri = Uri.parse(path);
  
              Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
              picMessageIntent.setPackage("com.android.mms");
              picMessageIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
              picMessageIntent.setType("image/png");
              picMessageIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              startActivity(picMessageIntent);
          }
      }
  
      @Override
      public void onText(CharSequence text) {
  
      }
  
      @Override
      public void swipeLeft() {
  
      }
  
      @Override
      public void swipeRight() {
  
      }
  
      @Override
      public void swipeDown() {
  
      }
  
      @Override
      public void swipeUp() {
  
      }
  </code></pre>
  
  <p>My Keyboard.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.inputmethodservice.KeyboardView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/keyboard"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      /&gt;
  </code></pre>
  
  <p>Styles.xml</p>
  
  <pre><code>&lt;resources&gt;
      &lt;!-- Base application theme. --&gt;
      &lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&gt;
          &lt;!-- Customize your theme here. --&gt;
          &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
          &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
          &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
      &lt;/style&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="CENSORED" &gt;
  
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;!-- Declares the input method service --&gt;
          &lt;service android:name=".CENSORED"
              android:label="@string/keyboard_name"
              android:permission="android.permission.BIND_INPUT_METHOD"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.view.InputMethod" /&gt;
              &lt;/intent-filter&gt;
              &lt;meta-data android:name="android.view.im"
                  android:resource="@xml/method" /&gt;
          &lt;/service&gt;
      &lt;/application&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;/manifest&gt;
  </code></pre>