Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflicting lint messages regarding paddingStart usage

Tags:

android

lint

After API 17 / RTL support was released, I added the following to my manifest

android:supportsRtl="true"

which caused Lint to rightfully give me these warnings wherever I had paddingLeft/Right in my views:

  • Consider adding android:paddingStart="8dp" to better support right-to-left layouts

  • Consider adding android:paddingEnd="8dp" to better support right-to-left layouts

I did this following the guidance found in this android-developers blogpost, which implied that we did not need to create a new layout-v17 file, but rather could just use both the paddingStart/End as well as the paddingLeft/Right attributes (the Left/Right were required to continue supporting a lower minSdk).


I just made the update to Android Studio 1.0 from the previous Beta version, and am noticing a new lint error which states:

  • Attribute paddingStart referenced here can result in a crash on some specific devices older than API 17 (current min is 7)

and the suggested fix is:

Override Resource in layout-v17

Which makes sense. However, after creating layout-v17 and removing the unused paddingStart/End from the main layout folder, the original Lint warnings have reappeared saying that I should use paddingStart/End. It seems like it does not understand that I have overrided the files in layout-v17.

Does anyone know how to solve what seems to be conflicting Lint error/warning messages? I know I can just tools:ignore the warning, but I am hoping for a "proper" solution.


Edit (1/19/15): There is an android issue that I imagine led to the new lint error being added to Android Studio. This suggests that the "crash on some specific devices" refers to a handful of Samsung tablets on API16 where paddingStart has its own definition and as such crashes when it tries to parse "8dp".

Some people in the above link have suggested to use the layout-ldrtl folder to handle the rtl direction, rather than using paddingStart and paddingEnd.

I've also had a suggestion elsewhere to override the LayoutInflator's Factory2 whenever you find that the user has a API16 tablet, and then manually set the attributes of all your views. This will certainly work, but it seems extremely "manual".

I unfortunately don't have access to one of these devices that crash, so I can't verify why I have not found anyone online suggesting simply putting paddingStart in /layout-v17/ folder, and paddingLeft in /layout/? Do the API16 Samsung tablets somehow still continue to crash despite paddingStart only being present in layout-v17?

like image 893
tabjsina Avatar asked Dec 12 '14 18:12

tabjsina


1 Answers

You're right about the root cause of the issue - Samsung defined a custom attribute for the id reserved for paddingStart or paddingEnd.

The way I by-passed this was to extract the padding properties and put them into a style. So instead of having different layouts for SDK<17 and SDK>=17, I have different styles for them (with paddingLeft&Right in values and paddingStart&End in values-v17).

This way, Lint will stop complaining about it.

like image 63
N.T. Avatar answered Oct 25 '22 13:10

N.T.