是否有可能在Android的定义随配置的XML常量 [英] Is it possible in android to define constants in XML that vary with configuration
问题描述
我感兴趣的具有Android的改变大小的XML布局依赖于横向或纵向观看(也许其他配置后)。
I am interested in having an XML layouts in Android change size depending on landscape or portrait viewing (and maybe other configurations later).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="@drawable/stream_bg_1px_wide"
android:layout_height="150dip" >
在这个例子中,我的只是的想改变150dip大小取决于横向还是纵向,不会改变任何东西。
In this example I just want to vary the 150dip size depending on landscape or portrait, not change anything else.
我使用的布局和布局地,我知道我可以在每一个这些文件夹中的重复布局,但使保持有点痛在它的变化。当我介绍更多的变种基于屏幕像素密度和尺寸,它只是变得更糟。
I am using layout and layout-land, and I know I could repeat the layout in each of those folders, but that makes maintaining changes in it a bit of a pain. When I introduce more variants based on screen density and size it just gets worse.
所以,我不知道是否有可能定义一个值(常量)在一个XML文件,并从我的布局,类似的颜色如何被定义的参考它
So, I wondered if it's possible to define a value (constant) in an XML file, and reference it from my layout, similar to how colors can be defined
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="shopper_background"> #FFFFFF</color>
</resources>
沿的线条......
along the lines of......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<value name="footer_size" >150</value>
</resources>
然后,我可以只复制该文件,以不同的价值观,在每一个配置。
Then I could just replicate that file, with different values, in each config.
感谢您的帮助
推荐答案
是的。维是在资源文件中一个公认的项目。因此,创建如RES /价值/ dimension.xml并把
Yes. A dimension is an accepted item in a resource file. So create e.g. res/values/dimension.xml and put
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="footer_size" >150dp</dimen>
</resources>
这篇关于是否有可能在Android的定义随配置的XML常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!