gia*_*200 5 android android-layout android-linearlayout android-xml android-resources
我有一个用于横向和纵向的布局.我有它/layout和/layout-land文件夹.唯一的区别是android:orientation.
我想只有1 xml,/layout因为它更容易维护.我想使用/values而/values-land不是.这可能吗?
我现在拥有的是(删除了不必要的代码):
<LinearLayout
android:orientation="horizontal"/>
Run Code Online (Sandbox Code Playgroud)
VS
<LinearLayout
android:orientation="vertical"/>
Run Code Online (Sandbox Code Playgroud)
我虽然喜欢这样的东西:
<LinearLayout
android:orientation="@xxxx/linear_orientation"/>
Run Code Online (Sandbox Code Playgroud)
作为一个终极解决方案,我还考虑过仅为此创建一个自定义样式LinearLayout(我不喜欢这个解决方案,但如果我不能使用另一个选项则必须使用它).
注意:我知道可以这样做java,但我正在寻找一个只有xml的解决方案.
Lei*_*Guo 13
我想在/ layout中只有1 xml,因为它更容易维护.我想改用/ values和/ values-land.这可能吗?
是的,这是可能的.您可以使用Style来实现这一目标.
/ values下styles.xml中的Style:
Run Code Online (Sandbox Code Playgroud)<style name="LinearLayoutOrientation" > <item name="android:orientation">vertical</item> </style>
/ values-land下styles.xml中的Style:
Run Code Online (Sandbox Code Playgroud)<style name="LinearLayoutOrientation" > <item name="android:orientation">horizontal</item> </style>
LinearLayout的最终xml代码:
<LinearLayout
style="@style/LinearLayoutOrientation"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
554 次 |
| 最近记录: |