I have a layout with a TextView and I want the android:gravity attribute value to be pulled from another resource file, android:gravity="@???/item_align", where item_align is the name of a resource in another xml file. The typical values used in a layout, center or bottom or bottom|center_horizontal don’t work. What type goes in the @???, integer works, if I replace the strings with the actual integer value (“center” replaced with 0x011). But, that’s not a good solution.
So, the question(s): How do I refer to the value in the layout file, and what does the item look like in the resource file?
<TextView
android:id="@+id/item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_margin="1dp"
android:layout_centerHorizontal="true"
android:gravity="@???/item_align"
android:text="65"
android:textSize="20sp"
android:typeface="sans"
android:textStyle="bold"
android:textColor="#000000" />
Concept:
integers.xml
Gravity values are all integer constanst, you have to look it up and define it in your integers.xml .
Example implementation:
in docs… Then you add to your integers.xml in res/values/:
and in your xml, do: