EditText Height Issue

2019-04-12 06:37发布

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条回答
smile是对你的礼貌
2楼-- · 2019-04-12 07:31

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.

查看更多
登录 后发表回答