引用另一个layout.xml文件,而无需复制它 [英] Referencing another layout.xml file without duplicating it

查看:209
本文介绍了引用另一个layout.xml文件,而无需复制它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提供一个活动的相同layout.xml文件为几个不同的限定符。我知道,有一种方法可以只引用一个现有layout.xml,而不是真正的将其复制并具有重复的。

I need to provide the same layout.xml file for an Activity for several different qualifiers. I know that there's a way to just reference one existing layout.xml instead of really copying it and having a duplicate one.

怎么会呢?找不到它在Android文档现在...: - /

But how? Can't find it in the Android docs right now... :-/

有人比我快?

编辑:虽然我发现这个解决方案我仍然还没有

although I found this "solution" I am still not there.

<?xml version="1.0" encoding="utf-8"?>
<merge>
    <include layout="@layout/main_ltr"/>
</merge>

我要指向不同预选赛的布局文件,而不是在同一预选赛另一个布局文件。 其背后原因:我指定的新的Andr​​oid 3.2预选赛被证明屏幕宽度预选赛。但在Android 3.0 / 3.1这不工作,我需要XLARGE,但我希望它是完全一样的文件,而不是副本!

I need to point to a different qualifiers's layout file, not to another layout file in the same qualifier. Reason behind it: I specified the new Android 3.2 qualifier by proving screen width qualifiers. But on Android 3.0/3.1 this does not work, I need xlarge there, but I want it to be exactly the SAME file, not a copy!

推荐答案

正确提问者具有XLARGE和SW-600dp一种布局文件,另一个用于所有的休息。反正这是我的情况时,我无意中发现了这个问题。

If I understood correctly asker has one layout file for xlarge and sw-600dp and another one for all the rest. Anyway that was my situation when I stumbled on this question.

一个可以通过创建文件夹的布局-XLARGE和布局-s600dp解决这个和放一布局文件中的每个但具有相同的内容。但一想不会有两个文件夹中显而易见的两个原因完全相同的文件。

One can solve this by creating folders layout-xlarge and layout-s600dp and put one layout file in each but with the same contents. But one would like not to have two exact same files in two folders for obvious reasons.

这是我对这个问题的解决方案。不要使布局XLARGE和布局,sw600dp文件都没有。比方说,你要创建与布局文件/res/layout/cool_activity.xml一个很酷的活动。在同一个文件夹中创建您的平板电脑的布局文件,但用不同的名称,如/res/layout/cool_activity_for_tablet.xml然后创建文件夹价值观XLARGE和价值观sw600dp与下面的内容在里面layout.xml文件

This is my solution for the problem. Dont make layout-xlarge and layout-sw600dp files at all. Let's say you're creating a cool activity with layout file /res/layout/cool_activity.xml. Create your tablet layout file in the same folder but with a different name, i.e. /res/layout/cool_activity_for_tablet.xml and then create folders values-xlarge and values-sw600dp with layout.xml files in it with the following content

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="cool_activity" type="layout">@layout/cool_activity_for_tablet</item>
</resources>

是的,你仍然有2个,这些具有相同的内容,但是这是愚蠢的内容并不布局本身可以是几百行的XML。

Yes you will still have 2 of these with the same content but this is dumb content not the layout itself which can be hundreds of lines of xml.

这篇关于引用另一个layout.xml文件,而无需复制它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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