简体   繁体   English

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

[英]how to import one xml file to another

i had an main.xml file and a cell_shape.xml file. 我有一个main.xml文件和一个cell_shape.xml文件。

in my main.XML i had this 在我的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" />

in my cell_shape.XML i had this 在我的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>

i had this error 我有这个错误

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

and i don't understand how do i correctly can import if it my main.xml 而且我不明白如何将main.xml正确导入

is there a tutorial on how to import different elements from one xml file to another? 有没有关于如何将不同元素从一个xml文件导入到另一个xml的教程?

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

Maybe this may help you? 也许这可以帮助您? I had a similar problem and it helped me. 我有一个类似的问题,它对我有帮助。 If it doesn't... sorry mate... don't have other answers 如果没有...对不起队友...没有其他答案

Try removing the id in include , So it looks just like this: 尝试删除includeid ,所以看起来像这样:

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

If it does not work, try enclosing the whole cell_shape with one LinearLayout or other type of layout. 如果不起作用,请尝试使用一个LinearLayout或其他类型的布局将整个cell_shape括起来。

By the way, for Android design uniformity, please use the color from this Android site . 顺便说一句,为确保Android设计的一致性,请使用此Android网站上的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM