diff --git a/java/res/values-xlarge/dimens.xml b/java/res/values-xlarge/dimens.xml
index 2c188bc0cd943863f18eb1f828e6720f3f7d1b27..69283202e6891602d8ab1c2cc0c16c51ac4b29ca 100644
--- a/java/res/values-xlarge/dimens.xml
+++ b/java/res/values-xlarge/dimens.xml
@@ -30,6 +30,7 @@
     <dimen name="keyboard_bottom_padding">0.0mm</dimen>
     <!-- key_height x 1.0 -->
     <dimen name="key_preview_height">13.0mm</dimen>
+    <dimen name="mini_keyboard_key_horizontal_padding">12dip</dimen>
     <!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. -->
     <!-- popup_key_height x 1.2 -->
     <dimen name="mini_keyboard_slide_allowance">15.6mm</dimen>
diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml
index cf2019ff8ad018fd1413eec42d0f085c7a0684f6..504e007e0a53bfe36286a562be4cd2fe02aa5337 100644
--- a/java/res/values/dimens.xml
+++ b/java/res/values/dimens.xml
@@ -30,6 +30,7 @@
     <dimen name="keyboard_bottom_padding">0.06in</dimen>
     <!-- key_preview_text_size_large x 2 -->
     <dimen name="key_preview_height">80sp</dimen>
+    <dimen name="mini_keyboard_key_horizontal_padding">8dip</dimen>
     <!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. -->
     <!-- popup_key_height x 1.2 -->
     <dimen name="mini_keyboard_slide_allowance">0.390in</dimen>
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 3b35c93d3a0a8e33093ea2f257376555c9591f9d..c2aa4ecba859585ef37364631ab59671618eb42c 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -136,11 +136,11 @@ public class Key {
      * This constructor is being used only for key in mini popup keyboard.
      */
     public Key(Resources res, Keyboard keyboard, CharSequence popupCharacter, int x, int y,
-            int edgeFlags) {
+            int width, int edgeFlags) {
         mKeyboard = keyboard;
         mHeight = keyboard.getRowHeight() - keyboard.getVerticalGap();
         mGap = keyboard.getHorizontalGap();
-        mWidth = keyboard.getKeyWidth() - mGap;
+        mWidth = width - mGap;
         mEdgeFlags = edgeFlags;
         mHintIcon = null;
         mManualTemporaryUpperCaseHintIcon = null;
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index b259e0c03b3eb5390116c983559202f773a1b54f..e7dd716fb9f3c4317d7abf7dbd0a097c63e2885d 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -692,7 +692,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
             // Draw key label
             if (label != null) {
                 // For characters, use large font. For labels like "Done", use small font.
-                final int labelSize = getLabelSizeAndSetPaint(label, key, paint);
+                final int labelSize = getLabelSizeAndSetPaint(label, key.mLabelOption, paint);
                 final int labelCharHeight = getLabelCharHeight(labelSize, paint);
 
                 // Vertical label text alignment.
@@ -828,13 +828,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
         mDirtyRect.setEmpty();
     }
 
-    private int getLabelSizeAndSetPaint(CharSequence label, Key key, Paint paint) {
+    public int getLabelSizeAndSetPaint(CharSequence label, int keyLabelOption, Paint paint) {
         // For characters, use large font. For labels like "Done", use small font.
         final int labelSize;
         final Typeface labelStyle;
         if (label.length() > 1) {
             labelSize = mLabelTextSize;
-            if ((key.mLabelOption & KEY_LABEL_OPTION_FONT_NORMAL) != 0) {
+            if ((keyLabelOption & KEY_LABEL_OPTION_FONT_NORMAL) != 0) {
                 labelStyle = Typeface.DEFAULT;
             } else {
                 labelStyle = Typeface.DEFAULT_BOLD;
@@ -1126,7 +1126,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
         // Remove gesture detector on mini-keyboard
         miniKeyboard.mGestureDetector = null;
 
-        Keyboard keyboard = new MiniKeyboardBuilder(getContext(), popupKeyboardResId, popupKey)
+        Keyboard keyboard = new MiniKeyboardBuilder(this, popupKeyboardResId, popupKey)
                 .build();
         miniKeyboard.setKeyboard(keyboard);
         miniKeyboard.setPopupParent(this);
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java
index 33d19602de55496dd87faf43aa5110c02bebb488..458a9eed4509b16056a23ea17a0ec7e0b6173d56 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboardBuilder.java
@@ -16,8 +16,12 @@
 
 package com.android.inputmethod.keyboard;
 
+import com.android.inputmethod.latin.R;
+
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.Paint;
+import android.graphics.Rect;
 
 import java.util.List;
 
@@ -25,6 +29,8 @@ public class MiniKeyboardBuilder {
     private final Resources mRes;
     private final Keyboard mKeyboard;
     private final CharSequence[] mPopupCharacters;
+    private final int mMiniKeyboardKeyHorizontalPadding;
+    private final int mKeyWidth;
     private final int mMaxColumns;
     private final int mNumRows;
     private int mColPos;
@@ -32,35 +38,61 @@ public class MiniKeyboardBuilder {
     private int mX;
     private int mY;
 
-    public MiniKeyboardBuilder(Context context, int layoutTemplateResId, Key popupKey) {
+    public MiniKeyboardBuilder(KeyboardView view, int layoutTemplateResId, Key popupKey) {
+        final Context context = view.getContext();
         mRes = context.getResources();
         final Keyboard keyboard = new Keyboard(context, layoutTemplateResId, null);
         mKeyboard = keyboard;
         mPopupCharacters = popupKey.mPopupCharacters;
-        final int numKeys = mPopupCharacters.length;
+        mMiniKeyboardKeyHorizontalPadding = (int)mRes.getDimension(
+                R.dimen.mini_keyboard_key_horizontal_padding);
+        mKeyWidth = getMaxKeyWidth(view, mPopupCharacters, mKeyboard.getKeyWidth());
         final int maxColumns = popupKey.mMaxPopupColumn;
+        mMaxColumns = maxColumns;
+        final int numKeys = mPopupCharacters.length;
         int numRows = numKeys / maxColumns;
         if (numKeys % maxColumns != 0) numRows++;
-        mMaxColumns = maxColumns;
         mNumRows = numRows;
         keyboard.setHeight((keyboard.getRowHeight() + keyboard.getVerticalGap()) * numRows
                 - keyboard.getVerticalGap());
-        // TODO: To determine key width we should pay attention to key label length.
         if (numRows > 1) {
             mColPos = numKeys % maxColumns;
             if (mColPos > 0) mColPos = maxColumns - mColPos;
             // Centering top-row keys.
-            mX = mColPos * (keyboard.getKeyWidth() + keyboard.getHorizontalGap()) / 2;
+            mX = mColPos * (mKeyWidth + keyboard.getHorizontalGap()) / 2;
         }
         mKeyboard.setMinWidth(0);
     }
 
+    private int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters, int minKeyWidth) {
+        Paint paint = null;
+        Rect bounds = null;
+        int maxWidth = 0;
+        for (CharSequence popupSpec : popupCharacters) {
+            final CharSequence label = PopupCharactersParser.getLabel(popupSpec.toString());
+            // If the label is single letter, minKeyWidth is enough to hold the label.
+            if (label.length() > 1) {
+                if (paint == null) {
+                    paint = new Paint();
+                    paint.setAntiAlias(true);
+                }
+                final int labelSize = view.getLabelSizeAndSetPaint(label, 0, paint);
+                paint.setTextSize(labelSize);
+                if (bounds == null) bounds = new Rect();
+                paint.getTextBounds(label.toString(), 0, label.length(), bounds);
+                if (maxWidth < bounds.width())
+                    maxWidth = bounds.width();
+            }
+        }
+        return Math.max(minKeyWidth, maxWidth + mMiniKeyboardKeyHorizontalPadding);
+    }
+
     public Keyboard build() {
         final Keyboard keyboard = mKeyboard;
         final List<Key> keys = keyboard.getKeys();
         for (CharSequence label : mPopupCharacters) {
             refresh();
-            final Key key = new Key(mRes, keyboard, label, mX, mY, getRowFlags());
+            final Key key = new Key(mRes, keyboard, label, mX, mY, mKeyWidth, getRowFlags());
             keys.add(key);
             advance();
         }
@@ -89,7 +121,7 @@ public class MiniKeyboardBuilder {
     private void advance() {
         final Keyboard keyboard = mKeyboard;
         // TODO: Allocate key position depending the precedence of popup characters.
-        mX += keyboard.getKeyWidth() + keyboard.getHorizontalGap();
+        mX += mKeyWidth + keyboard.getHorizontalGap();
         if (mX > keyboard.getMinWidth())
             keyboard.setMinWidth(mX);
         mColPos++;