38

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?

Community
  • 1
  • 1
tabjsina
  • 1,582
  • 15
  • 26

2 Answers2

1

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.

N.T.
  • 2,601
  • 1
  • 14
  • 20
  • I made a habit of having everything using start/end defined in styles placed under values-17 or higher. It is not absolutely necessary in all cases, but it buys me peace of mind and possibly time by not having to worry about it. – N.T. Jan 07 '17 at 04:36
0

Its just a suggestion. I hope you have solved your problem by now. If you set your minimum SDK level below 4.1, then you have to explicitly mention the padding as paddingLeft and paddingStart. For SDK level above 4.1, you can use paddingStart. I am guessing (as I have never faced it before), as you set your SDK level to 2.2 or below 4.1, android sdk level is going crazy.

  • Unfortunately it is not that simple. As mentioned in my question, I originally had both until Android Studio 1.0 update introduced a new lint error stating that we should not have paddingStart in xml files in any version below API 17. The lint error I posted says that very clearly and is backed up by this issue: (https://code.google.com/p/android/issues/detail?id=60055). – tabjsina Jan 19 '15 at 16:44