diff --git a/java/res/layout/input_basic.xml b/java/res/layout/input_basic.xml
index 7b85bae944152afaca3758c62db38ea06b9782fc..86ae82d5113594170169a628cfd55107e268ac9d 100644
--- a/java/res/layout/input_basic.xml
+++ b/java/res/layout/input_basic.xml
@@ -25,6 +25,7 @@
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:padding="0dip"
         android:background="@drawable/keyboard_background"
 
         latin:keyBackground="@drawable/btn_keyboard_key"
diff --git a/java/res/layout/input_basic_highcontrast.xml b/java/res/layout/input_basic_highcontrast.xml
index d9200fd5e8f6c8ff80dbcbd57fa60d142ce24044..03b22ef076f5239df5ec71892d4e6aabc8eafc25 100644
--- a/java/res/layout/input_basic_highcontrast.xml
+++ b/java/res/layout/input_basic_highcontrast.xml
@@ -21,11 +21,11 @@
 <com.android.inputmethod.keyboard.LatinKeyboardView
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
-
         android:id="@+id/LatinkeyboardBaseView"
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:padding="0dip"
         android:background="@android:color/black"
 
         latin:keyBackground="@drawable/btn_keyboard_key3"
diff --git a/java/res/layout/input_gingerbread.xml b/java/res/layout/input_gingerbread.xml
index 6233e6dc67f308291af71ba98aa5521a56dc495e..9332f9ddf459f08c3810b569ad74fab8685cfa9d 100644
--- a/java/res/layout/input_gingerbread.xml
+++ b/java/res/layout/input_gingerbread.xml
@@ -25,8 +25,7 @@
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:paddingTop="@dimen/keyboard_top_padding"
-        android:paddingBottom="@dimen/keyboard_bottom_padding"
+        android:padding="0dip"
         android:background="@drawable/keyboard_dark_background"
 
         latin:keyBackground="@drawable/btn_keyboard_key_gingerbread"
diff --git a/java/res/layout/input_honeycomb.xml b/java/res/layout/input_honeycomb.xml
index 96b10b7ccf73b834509d19a608bc647b2d4dd5c9..42bedb43c89ced3fffd035075c8cfc8754d7d145 100644
--- a/java/res/layout/input_honeycomb.xml
+++ b/java/res/layout/input_honeycomb.xml
@@ -25,8 +25,7 @@
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:paddingTop="@dimen/keyboard_top_padding"
-        android:paddingBottom="@dimen/keyboard_bottom_padding"
+        android:padding="0dip"
         android:background="@drawable/keyboard_background_holo"
 
         latin:keyBackground="@drawable/btn_keyboard_key_honeycomb"
diff --git a/java/res/layout/input_stone_bold.xml b/java/res/layout/input_stone_bold.xml
index 6fdc93855f4777985041cd7c89d21eb747a92d90..22ac14eb129dfffa4b024817c472cbae342bef74 100644
--- a/java/res/layout/input_stone_bold.xml
+++ b/java/res/layout/input_stone_bold.xml
@@ -25,6 +25,7 @@
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:padding="0dip"
         android:background="@drawable/keyboard_background"
 
         latin:keyBackground="@drawable/btn_keyboard_key_stone"
@@ -33,5 +34,5 @@
         latin:shadowColor="@color/latinkeyboard_key_color_white"
         latin:keyLetterStyle="bold"
         latin:colorScheme="black"
-        latin:popupLayout="@layout/input_stone_popup"
+        latin:popupLayout="@layout/keyboard_popup_stone"
         />
diff --git a/java/res/layout/input_stone_normal.xml b/java/res/layout/input_stone_normal.xml
index 6ae9aed550556b0e9a30d5b4ac8efacd64139fc2..8baecabdbd870d19a630ee1f34f43b8afdb0165f 100644
--- a/java/res/layout/input_stone_normal.xml
+++ b/java/res/layout/input_stone_normal.xml
@@ -25,6 +25,7 @@
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:padding="0dip"
         android:background="@drawable/keyboard_background"
 
         latin:keyBackground="@drawable/btn_keyboard_key_stone"
@@ -32,5 +33,5 @@
         latin:keyTextColorDisabled="#FF808080"
         latin:shadowColor="@color/latinkeyboard_key_color_white"
         latin:colorScheme="black"
-        latin:popupLayout="@layout/input_stone_popup"
+        latin:popupLayout="@layout/keyboard_popup_stone"
         />
diff --git a/java/res/layout/input_stone_popup.xml b/java/res/layout/keyboard_popup_stone.xml
similarity index 96%
rename from java/res/layout/input_stone_popup.xml
rename to java/res/layout/keyboard_popup_stone.xml
index b4da0453672107073bdd5ceaacdd5f2226b911b0..e6acee374b7acbca92934162c2b7ba1ea694d786 100644
--- a/java/res/layout/input_stone_popup.xml
+++ b/java/res/layout/keyboard_popup_stone.xml
@@ -36,6 +36,5 @@
             latin:keyBackground="@drawable/btn_keyboard_key_stone"
             latin:keyTextColor="@color/latinkeyboard_key_color_black"
             latin:shadowColor="@color/latinkeyboard_key_color_white"
-            latin:popupLayout="@layout/input_stone_popup"
         />
 </LinearLayout>
diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml
index 7df124bfc605e80f4dae497f8b06cbd32127f3ed..6954ba2ae72672842d0962a3ffceb04d2d0b1cc0 100644
--- a/java/res/values-land/dimens.xml
+++ b/java/res/values-land/dimens.xml
@@ -27,6 +27,7 @@
     <dimen name="popup_key_height">0.270in</dimen>
     <dimen name="keyboard_top_padding">0.0in</dimen>
     <dimen name="keyboard_bottom_padding">0.0in</dimen>
+    <dimen name="keyboard_horizontal_edges_padding">0.0in</dimen>
     <dimen name="candidate_strip_height">38dip</dimen>
     <dimen name="candidate_strip_fading_edge_length">63dip</dimen>
     <dimen name="spacebar_vertical_correction">2dip</dimen>
diff --git a/java/res/values-xlarge-land/dimens.xml b/java/res/values-xlarge-land/dimens.xml
index ba42ddde6aaa94745751b81fc0fcf7549850246a..fd6b1f386be410965a5ae3a8f4c1fe39d7b826d2 100644
--- a/java/res/values-xlarge-land/dimens.xml
+++ b/java/res/values-xlarge-land/dimens.xml
@@ -28,6 +28,7 @@
     <dimen name="popup_key_height">13.0mm</dimen>
     <dimen name="keyboard_top_padding">1.1mm</dimen>
     <dimen name="keyboard_bottom_padding">0.0mm</dimen>
+    <dimen name="keyboard_horizontal_edges_padding">0.0mm</dimen>
 
     <dimen name="key_letter_size">28dip</dimen>
     <dimen name="key_label_text_size">20dip</dimen>
diff --git a/java/res/values-xlarge/dimens.xml b/java/res/values-xlarge/dimens.xml
index cdb6e89a48038b5a96726e5e9f879c138e761b8d..0dc5621ffbe9916d34202d0a4c97eb2e3316c097 100644
--- a/java/res/values-xlarge/dimens.xml
+++ b/java/res/values-xlarge/dimens.xml
@@ -28,6 +28,7 @@
     <dimen name="popup_key_height">10.0mm</dimen>
     <dimen name="keyboard_top_padding">1.1mm</dimen>
     <dimen name="keyboard_bottom_padding">0.0mm</dimen>
+    <dimen name="keyboard_horizontal_edges_padding">0.0mm</dimen>
     <dimen name="mini_keyboard_horizontal_padding_holo">40dip</dimen>
     <dimen name="mini_keyboard_key_horizontal_padding">12dip</dimen>
     <!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. -->
diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml
index 2cfc17de97727abf1d5548ee5a196135266c6c18..767dc4aa94a00e86af4ee1764646e87a8aea050d 100644
--- a/java/res/values/dimens.xml
+++ b/java/res/values/dimens.xml
@@ -28,6 +28,7 @@
     <dimen name="popup_key_height">0.325in</dimen>
     <dimen name="keyboard_top_padding">0.00in</dimen>
     <dimen name="keyboard_bottom_padding">0.06in</dimen>
+    <dimen name="keyboard_horizontal_edges_padding">0.0in</dimen>
     <dimen name="mini_keyboard_horizontal_padding">16dip</dimen>
     <dimen name="mini_keyboard_horizontal_padding_holo">32dip</dimen>
     <dimen name="mini_keyboard_key_horizontal_padding">8dip</dimen>
diff --git a/java/res/xml/kbd_qwerty_row3.xml b/java/res/xml/kbd_qwerty_row3.xml
index 26608fd716732567ae0d4e1c35b322b33cb81e36..27016aff09658f922cef725c89bd547216c68833 100644
--- a/java/res/xml/kbd_qwerty_row3.xml
+++ b/java/res/xml/kbd_qwerty_row3.xml
@@ -26,8 +26,10 @@
     >
         <Key
             latin:keyStyle="shiftKeyStyle"
-            latin:keyWidth="15%p"
+            latin:keyWidth="13%p"
             latin:keyEdgeFlags="left" />
+        <Spacer
+            latin:horizontalGap="2%p" />
         <Key
             latin:keyLabel="z"
             latin:popupCharacters="@string/alternates_for_z" />
@@ -46,9 +48,11 @@
             latin:popupCharacters="@string/alternates_for_n" />
         <Key
             latin:keyLabel="m" />
+        <Spacer
+            latin:horizontalGap="2%p" />
         <Key
             latin:keyStyle="deleteKeyStyle"
-            latin:keyWidth="15%p"
+            latin:keyWidth="13%p"
             latin:keyEdgeFlags="right" />
     </Row>
 </merge>
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 418188209cef76b4d3080cacfc1f0ccf8880399f..f720334f1676ce87741eaeb6f8d2265b3f7b2b2e 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -165,7 +165,9 @@ public class Keyboard {
         GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
         GRID_SIZE = GRID_WIDTH * GRID_HEIGHT;
 
-        mDisplayWidth = width;
+        final int horizontalEdgesPadding = (int)res.getDimension(
+                R.dimen.keyboard_horizontal_edges_padding);
+        mDisplayWidth = width - horizontalEdgesPadding * 2;
         mDisplayHeight = height;
 
         mDefaultHorizontalGap = 0;
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
index 62e6f302def7ede23ed09b5b9cf19436b3ab4144..9c556c309132a03260aba7519456fc5b14a4a65d 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
@@ -122,6 +122,7 @@ public class KeyboardParser {
     private final Keyboard mKeyboard;
     private final Resources mResources;
 
+    private int mHorizontalEdgesPadding;
     private int mCurrentX = 0;
     private int mCurrentY = 0;
     private int mMaxRowWidth = 0;
@@ -132,6 +133,7 @@ public class KeyboardParser {
     public KeyboardParser(Keyboard keyboard, Resources res) {
         mKeyboard = keyboard;
         mResources = res;
+        mHorizontalEdgesPadding = (int)res.getDimension(R.dimen.keyboard_horizontal_edges_padding);
     }
 
     public int getMaxRowWidth() {
@@ -151,6 +153,7 @@ public class KeyboardParser {
                 final String tag = parser.getName();
                 if (TAG_KEYBOARD.equals(tag)) {
                     parseKeyboardAttributes(parser);
+                    startKeyboard();
                     parseKeyboardContent(parser, mKeyboard.getKeys());
                     break;
                 } else {
@@ -520,25 +523,32 @@ public class KeyboardParser {
         throw new NonEmptyTag(tag, parser);
     }
 
+    private void startKeyboard() {
+        mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_top_padding);
+    }
+
     private void startRow(Row row) {
         mCurrentX = 0;
+        setSpacer(mHorizontalEdgesPadding);
         mCurrentRow = row;
     }
 
     private void endRow() {
         if (mCurrentRow == null)
             throw new InflateException("orphant end row tag");
+        setSpacer(mHorizontalEdgesPadding);
+        if (mCurrentX > mMaxRowWidth)
+            mMaxRowWidth = mCurrentX;
         mCurrentY += mCurrentRow.mDefaultHeight;
         mCurrentRow = null;
     }
 
     private void endKey(Key key) {
         mCurrentX += key.mGap + key.mWidth;
-        if (mCurrentX > mMaxRowWidth)
-            mMaxRowWidth = mCurrentX;
     }
 
     private void endKeyboard(int defaultVerticalGap) {
+        mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_bottom_padding);
         mTotalHeight = mCurrentY - defaultVerticalGap;
     }
 
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index cc14589f6afc20bb82822a70989885cf364a8729..e82796bf47646a8759fd334cfccd06bc30052425 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -1056,7 +1056,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
         mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
     }
 
-    private void onDoubleTapShiftKey(PointerTracker tracker) {
+    private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) {
         // When shift key is double tapped, the first tap is correctly processed as usual tap. And
         // the second tap is treated as this double tap event, so that we need not mark tracker
         // calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue.