如何将一个xml文件导入另一个

时间:2012-11-21 10:48:33

标签: android android-layout

我有一个main.xml文件和一个cell_shape.xml文件。

在我的main.XML中我有这个

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:weightSum="100" >

<include
    android:id="tables"
    layout="@layout/cell_shape" />

在我的cell_shape.XML中我有这个

    <?xml version="1.0" encoding="utf-8"?>
   <shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/tables"
    android:shape= "rectangle"  >
        <solid android:color="#000"/>
        <stroke android:width="1dp"  android:color="#ff9"/>
</shape>

我有这个错误

Exception raised during rendering: You must specify a valid layout
 reference. The layout ID @layout/cell_shape is not valid. Couldn't
 resolve resource @layout/cell_shape Exception details are logged in
 Window > Show View > Error Log

我不明白如果我的main.xml

我怎么能正确导入

是否有关于如何将不同元素从一个xml文件导入另一个xml文件的教程?

2 个答案:

答案 0 :(得分:0)

http://www.xml.com/pub/a/2002/07/31/xinclude.html

也许这对你有帮助吗?我有类似的问题,它帮助了我。如果没有...对不起伙伴......没有其他答案

答案 1 :(得分:0)

尝试删除id中的include,所以它看起来像这样:

<include
    layout="@layout/cell_shape" />

如果不起作用,请尝试用一个LinearLayout或其他类型的布局封装整个cell_shape。

顺便说一句,对于Android设计的一致性,请使用this Android site中的颜色。