@@ -75,8 +75,17 @@ public Cocos2dxEditBoxHelper(ResizeLayout layout) {
7575 Cocos2dxEditBoxHelper .mEditBoxArray = new SparseArray <Cocos2dxEditBox >();
7676 }
7777
78+ public static int convertToSP (float point ){
79+ Resources r = mCocos2dxActivity .getResources ();
7880
79- public static int createEditBox (final int left , final int top , final int width , final int height ) {
81+ int convertedValue = (int )TypedValue .applyDimension (
82+ TypedValue .COMPLEX_UNIT_SP , point , r .getDisplayMetrics ());
83+
84+ return convertedValue ;
85+
86+ }
87+
88+ public static int createEditBox (final int left , final int top , final int width , final int height , final float scaleX ) {
8089 final int index = mViewTag ;
8190 mCocos2dxActivity .runOnUiThread (new Runnable () {
8291 @ Override
@@ -92,6 +101,17 @@ public void run() {
92101 editBox .setBackgroundColor (Color .TRANSPARENT );
93102 editBox .setTextColor (Color .WHITE );
94103 editBox .setSingleLine ();
104+ editBox .setOpenGLViewScaleX (scaleX );
105+ Resources r = mCocos2dxActivity .getResources ();
106+ float density = r .getDisplayMetrics ().density ;
107+ int paddingBottom = (int )(height * 0.33f / density );
108+ paddingBottom = convertToSP (paddingBottom - 5 * scaleX / density );
109+ paddingBottom = paddingBottom / 2 ;
110+ int paddingTop = paddingBottom ;
111+ int paddingLeft = (int )(5 * scaleX / density );
112+ paddingLeft = convertToSP (paddingLeft );
113+
114+ editBox .setPadding (paddingLeft ,paddingTop , 0 , paddingBottom );
95115
96116
97117 FrameLayout .LayoutParams lParams = new FrameLayout .LayoutParams (
@@ -101,7 +121,7 @@ public void run() {
101121 lParams .leftMargin = left ;
102122 lParams .topMargin = top ;
103123 lParams .width = width ;
104- lParams .height = height + 20 ;
124+ lParams .height = height ;
105125 lParams .gravity = Gravity .TOP | Gravity .LEFT ;
106126
107127 mFrameLayout .addView (editBox , lParams );
@@ -222,7 +242,10 @@ public void run() {
222242 }
223243 //TODO: The font size is not the same across all the anroid devices...
224244 if (fontSize >= 0 ){
225- editBox .setTextSize (TypedValue .COMPLEX_UNIT_SP , fontSize );
245+ float density = mCocos2dxActivity .getResources ().getDisplayMetrics ().density ;
246+ // Log.e("XXX", "density is " + density);
247+ editBox .setTextSize (TypedValue .COMPLEX_UNIT_SP ,
248+ fontSize / density );
226249 }
227250 editBox .setTypeface (tf );
228251 }
0 commit comments