Target emoji size 48 dp
// ------------ EMOJI PICKER
// target emoji size
int finalWidth=xxx,finalHeight=yyy; // final value for IME View
int orientationIdx = (cfg.orientation == Configuration.ORIENTATION_PORTRAIT) ? 0 : 1;
float density = context.getResources().getDisplayMetrics().density; //
final float targetEmojiSize = 48; // dp
//final float targetEmojiSize = (orientationIdx==0) ? 48f : 40f; // orientationIdx==0 -> portrait
//final float targetEmojiWidthPx = targetEmojiSize * (mXdpi / 160f);
//final float targetEmojiHeightPx = targetEmojiSize * (mYdpi / 160f);
//emojiGridColumns = Math.max(1, (int) (finalWidth/targetEmojiWidthPx));
//emojiGridRows = Math.max(1, finalHeight/targetEmojiHeightPx;
float targetEmojiSizePx = targetEmojiSize*density; // landscape too small
//float targetEmojiSizePx = (orientationIdx==0) ?
// targetEmojiSize * (mYdpi / 160f) :
// targetEmojiSize * (mXdpi / 160f) ;
emojiGridColumns = Math.max(3, (int) (finalWidth/targetEmojiSizePx));
//emojiGridRows = Math.max(1f,
// ((finalHeight*0.8f)/targetEmojiSizePx)-1f); // we just use 0.8 of finalHeight
emojiGridRows = (orientationIdx==0) ?
Math.max(1f,
((finalHeight*0.8f)/targetEmojiSizePx)) :
Math.max(1f,
((finalHeight*0.8f)/targetEmojiSizePx)-1)
; // we just use 0.8 of finalHeight
Log.e("dedetok", "targetEmojiSize "+targetEmojiSize+" targetEmojiSizePx "+targetEmojiSizePx); // debug
Log.e("dedetok", "finalWidth "+finalWidth+" finalHeight "+finalHeight); // debug
Log.e("dedetok", "emojiGridColumns "+emojiGridColumns+" emojiGridRows "+emojiGridRows); // debug
Note, you can remove *0.8f, in this context, the emoji only occupied 0.8 of finalHeight, not full. -1 is magic forcing internal emoji picker to reduce row and recalculate the emoji size.