android–EditText的大小不适合内容

android–EditText的大小不适合内容,第1张

概述我对动态创建的EditText有一点问题,我通过我创建的小键盘输入文本,取代原来的Android.文本是使用append插入的,但EditText的大小不适合文本.为什么?使用此解决方案:EditTextet=newEditText(myContext);LayoutParamsparams=newLayoutParams(LayoutParams.WRAP_CONTENT,L

我对动态创建的EditText有一点问题,我通过我创建的小键盘输入文本,取代原来的Android.文本是使用append插入的,但EditText的大小不适合文本.为什么?

使用此解决方案:

EditText et = new EditText(myContext);LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); et.setLayoutParams(params);

我有这个错误:

E/AndroIDRuntime(9544): FATAL EXCEPTION: mainE/AndroIDRuntime(9544): java.lang.classCastException: androID.vIEw.VIEwGroup$LayoutParams cannot be cast to androID.Widget.tableRow$LayoutParamsE/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)

解决方法:

import androID.Widget.linearLayout.LayoutParams;

将参数添加到WRAP_CONTENT.并设置所需的高度布局,填充或包裹.第一个是宽度,第二个是高度.

 EditText et = new EditText(myContext); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); et.setLayoutParams(params);

总结

以上是内存溢出为你收集整理的android – EditText的大小不适合内容全部内容,希望文章能够帮你解决android – EditText的大小不适合内容所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1116930.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存