Issue
I have a layout which is used on both landscape and portrait. I have it in /layout and /layout-land folders. The only difference is the android:orientation.
I would like to have only 1 xml in /layout because it is easier to maintain. I'd like to use /values and /values-land instead. Is this possible?
What I have now is (unnecessary code removed):
<LinearLayout
android:orientation="horizontal"/>
vs
<LinearLayout
android:orientation="vertical"/>
I though about something like:
<LinearLayout
android:orientation="@xxxx/linear_orientation"/>
As an ultimate solution I also thought about creating a custom style only for this LinearLayout (I don't like this solution, but will have to use it if I can't fine another option).
Note: I know it is possible to do it on java, but I'm looking for a xml-only solution.
Solution
I would like to have only 1 xml in /layout because it is easier to maintain. I'd like to use /values and /values-land instead. Is this possible?
Yes, it's possible. You can use Style to achieve that.
The Style in the styles.xml under /values:
<style name="LinearLayoutOrientation" > <item name="android:orientation">vertical</item> </style>
The Style in the styles.xml under /values-land:
<style name="LinearLayoutOrientation" > <item name="android:orientation">horizontal</item> </style>
Your final xml code for LinearLayout:
<LinearLayout
style="@style/LinearLayoutOrientation"/>
Answered By - Lei Guo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.