在Android中存储的XML文件的尺寸 [英] Storing dimensions in xml file in Android

查看:330
本文介绍了在Android中存储的XML文件的尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一直使用同一个维度中的所有的意见,我的Andr​​oid应用程序(例如,20dp的左边缘)。如果我使用的HTML,我会简单地使用一个CSS文件,但我在如何做到这一点在Android上的损失。

I am trying to consistently use the same dimension in all the views in my android app (e.g., a left margin of 20dp). If I were using HTML, I would simply use a CSS file, but I am at a loss of how to do this on Android.

有没有一种方法可以让我在里面RES /值的xml文件存储此值,然后用它的布局?

Is there a way I can store this value in a xml file inside res/values and then use it in layouts?

例如,我想将它们存储在strings.xml中像

e.g., I thought of storing them in strings.xml like

<string name="app_wide_left_padding">20dp</string>

,然后使用layout.xml以下文本

and then using the following text in layout.xml

android:paddingLeft="@string/app_wide_left_padding"

但我不知道它会工作。我是在正确的轨道?

but I am not sure it will work. Am I on the right track?

在此先感谢您的回答。

推荐答案

创建一个名为RES /价值/ dimens.xml

Create a file called res/values/dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="icon_width">55dip</dimen>
    <dimen name="icon_height">55dip</dimen>
    <dimen name="photo_width">170dip</dimen>
    <dimen name="photo_height">155dip</dimen>
</resources>

然后引用它们在你的其他的xml:

Then reference them in your other xml:

android:padding="@dimen/icon_width">

这篇关于在Android中存储的XML文件的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆