For questions about the behavior of markup in android - if in versions after lolipop everything works as it should, and before lolipop markup becomes clumsy, how to fix it?

Specifically, there is a recyclerView list, items in it, and so in the version after 5 everything looks as it should.

If I launch in versions below (I tried on 4.1.1 and 4.2), then the indicator showing the number of likes moves down to the left.

The markup is the same, as such bugs are corrected at all? To write in some way separately for the version below the 5th, I do not understand.

  • 2
    Show the markup. - Yuriy SPb

2 answers 2

Under such cases, write layout.xml with the same name only for the API version above ie. layout.xml written layout.xml with the correct view for a newer API, we put it in a folder called layout-v19 , everything above version 19 inclusive will be displayed as stated in this layout

  • one
    the solution is correct, just the opposite - such markup will be applied on API19 and higher . See the off-line tutorial , in particular Table2, the platform Level row (at the very end of the table) - pavlofff
  • @pavlofff thanks for the comment, corrected. - Evgeny Suetin
  • one
    not quite right. It is necessary not to name the layout-v19.xml , but to put the markup file for the 19+ API in the layout-v19 , and the file should be called the same — layout.xml - Vladyslav Matviienko

It is worth exploring the topic Providing alternative resources if the problems are related to objective reasons, such as another parsing of the same attributes to newer APIs or other parameters in the subject, for example, the type and size of widgets. In your case, the alternative resource will be API version.

It is also possible that markup uses attributes that are not supported in older APIs (like android:layout_marginStart supported with API17). Such attributes are ignored when parsing markup on older APIs and, of course, do not perform their functions.