Padding doesn't work on some devices

耗尽温柔 提交于 2021-01-27 03:54:29

问题


I had a strange problems during the set padding to EditText. xml looks like this:

<EditText
    android:layout_width="270dp"
    android:layout_height="55dp"
    android:ems="10"
    android:id="@+id/etEmail"
    android:textStyle="bold"
    android:layout_gravity="center_vertical"
    android:textColor="#FFFFFF"
    android:hint="Or Use your Email"
    android:inputType="textEmailAddress"
    android:layout_alignLeft="@+id/textView6"
    android:layout_alignStart="@+id/textView6"
    android:textColorHint="#FFFFFF"
    android:background="@drawable/line_white"
    android:paddingLeft="16.5dp"
    android:layout_marginTop="10dp"
    android:paddingRight="2dp" />

Here is the screenshot from Samsung Note 2 (Android 5.0.1):

enter image description here

... and LG G3 (Android 4.4.2):

enter image description here

As you can see, android:paddingLeft doesn't work for LG.

What could be the reason?

Thanks.


UPD: Layout bounds (LG):

enter image description here


回答1:


EditText padding via xml doesn't work after update to API level 21.
But EditText padding works, if it define programmatically.

editText.setPadding(10, 0, 0, 0);

You can track this issue on android issue tracker.

There are some other alternates too, discussed in the issue tracker thread.




回答2:


I've noticed this on the HTC One X. This doesn't fix your particular issue, but changing paddingStart to paddingLeft worked for me.




回答3:


This is dpi device problem. Make use of "dimen" folder, give different dp for various device screen sizes. Sure this will solve your problem.

android:paddingLeft="@dimen/yourValueName"


来源:https://stackoverflow.com/questions/30092150/padding-doesnt-work-on-some-devices

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