EditText Height Issue

岁酱吖の 提交于 2020-01-23 01:42:47

问题


I am trying to set smaller height of EditText but still have not managed it. Here is my source:

<EditText android:layout_width="150dp" android:layout_height="20dp"
      android:singleLine="true" android:textSize="10dp" />

This code cuts out text and a white rectangular shape appears around EditText control. I have also tried maxHeight/minHeight properties, but did not worked either. If anybody have solved this issue, please help.

Or is this is the bug in the android? I can not even resize Spinner, same happens as with EditText.

Thanks

Irfan


回答1:


You are probably seeing bizarre orange rectangular shapes within the field when testing in the emulator ?

If so then I have managed to work out some basic rule-of-thumb on size settings. Your textSize needs to be a little bigger. Try 30dp.

With some experimentation I have found that if you use "dp" and apply this rule of thumb, it should work for EditText fields.

textSize x 3= layout_height

I say rule of thumb because the minimum height before the field "breaks" again is about 29dp. So, for example if you have textSize="10dp", then layout_height="30dp", or textSize="12dp", then layout_height="36dp". You can have smaller textSizes, but it becomes illegible lower than 9dp. I found this works well in relative_layouts with default fonts.



来源:https://stackoverflow.com/questions/4360236/edittext-height-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!