3

Gravity value must be stored in a resource file because I have a multi-language app. (Arabic/English) which will affect the layout direction from ltr to rtl.

I used to do the same approach with eclipse adt successfully.

Error says: Cannot resolve flag. Validate resource references inside android xml files.

Structure

Layout

integers.xml

integers.xml

hasan
  • 23,815
  • 10
  • 63
  • 101
  • 1
    I don't think you have to use `gravity`. See http://android-developers.blogspot.it/2013/03/native-rtl-support-in-android-42.html – Phantômaxx Feb 09 '15 at 08:39
  • good point. but the approach at my answer just worked. even that the error is still there but I can run the app. and its doing the effect that I want. – hasan Feb 09 '15 at 09:02
  • It looks like google try to push developers to use the supportRtl attributes for the application item in the manifest. thats why the gravity attribute value is marked red on the xml layout file even it is not an error and the app builds and runs successfully! – hasan Feb 09 '15 at 14:18

2 Answers2

0

I recognised later that even that line highlighted with red which is the color for errors it can compile and run.

Apparently since the new SDK API supports language directions by providing the supportRtl attributes in the manifest. Google tries to encourage developers to use it and discourage them to keep using gravity in this way to implement languages direction. That's why it marked with Red.

hasan
  • 23,815
  • 10
  • 63
  • 101
0

You can create two styles (in styles.xml) in the /values and /values-sw600dp folder

/values/styles.xml

 <style name = "AppContainerLayout">
     <item name = "android:gravity">top|start</item>
 </style>

/values-sw600dp/styles.xml  

<style name = "AppContainerLayout">
    <item name = "android:gravity">center</item>
</style>

And just use in layout

<LinearLayout
             style = "@ style/AppContainerLayout"
             android:layout_width = "match_parent"
             android:layout_height = "wrap_content"
             android:orientation = "vertical">

             // childs
</LinearLayout>
Zakhar Rodionov
  • 1,398
  • 16
  • 18