我有一個動態創建的EditText的小問題,我通過我創建的小鍵盤輸入文本,取代原來的Android。文本是插入的附加,但EditText的大小不適合文本。爲什麼?EditText的大小不適合內容
與此解決方案:
EditText et = new EditText(myContext);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
et.setLayoutParams(params);
我有這樣的錯誤:
E/AndroidRuntime(9544): FATAL EXCEPTION: main
E/AndroidRuntime(9544): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.TableRow$LayoutParams
E/AndroidRuntime(9544): at android.widget.TableRow.mapIndexAndColumns(TableRow.java:162)
E/AndroidRuntime(9544): at android.widget.TableRow.getVirtualChildCount(TableRow.java:147)
E/AndroidRuntime(9544): at android.widget.TableRow.getColumnsWidths(TableRow.java:287)
E/AndroidRuntime(9544): at android.widget.TableLayout.findLargestCells(TableLayout.java:500)
E/AndroidRuntime(9544): at android.widget.TableLayout.measureVertical(TableLayout.java:465)
E/AndroidRuntime(9544): at android.widget.TableLayout.onMeasure(TableLayout.java:431)
E/AndroidRuntime(9544): at android.view.View.measure(View.java:12723)
E/AndroidRuntime(9544): at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1163)
E/AndroidRuntime(9544): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(9544): at android.widget.ScrollView.onMeasure(ScrollView.java:312)
E/AndroidRuntime(9544): at android.view.View.measure(View.java:12723)
E/AndroidRuntime(9544): at android.widget.HorizontalScrollView.measureChildWithMargins(HorizontalScrollView.java:1159)
E/AndroidRuntime(9544): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(9544): at android.widget.HorizontalScrollView.onMeasure(HorizontalScrollView.java:303)
E/AndroidRuntime(9544): at android.view.View.measure(View.java:12723)
E/AndroidRuntime(9544): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
E/AndroidRuntime(9544): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(9544): at android.view.View.measure(View.java:12723)
E/AndroidRuntime(9544): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
E/AndroidRuntime(9544): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(9544): at android.view.View.measure(View.java:12723)
E/AndroidRuntime(9544): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
E/AndroidRuntime(9544): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
E/AndroidRuntime(9544): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
E/AndroidRuntime(9544): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
E/AndroidRuntime(9544): at android.view.View.measure(View.java:12723)
E/AndroidRuntime(9544): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
E/AndroidRuntime(9544): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(9544): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
E/AndroidRuntime(9544): at android.view.View.measure(View.java:12723)
E/AndroidRuntime(9544): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
E/AndroidRuntime(9544): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
E/AndroidRuntime(9544): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(9544): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(9544): at android.app.ActivityThread.main(ActivityThread.java:4624)
E/AndroidRuntime(9544): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(9544): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(9544): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
E/AndroidRuntime(9544): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
E/AndroidRuntime(9544): at dalvik.system.NativeStart.main(Native Method)
是的,我創建了一個小鍵盤和禁用經典的Android – whiteTIGER 2012-08-13 10:17:56
使用WRAP_CONTENT – Doomsknight 2012-08-13 10:23:00
我要自動調整由內容的EditText上,我不得不這樣做動態java中 – whiteTIGER 2012-08-13 10:30:07