【问题标题】:Include directive is not been including the required content包含指令未包含所需内容
【发布时间】:2013-02-20 20:23:40
【问题描述】:

您好,我是 android 编程的新手,我正在玩 include 标签。

我有一个名为 companylogo 的布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <!-- Logo Start-->
    <ImageView android:src="@drawable/logo2"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginLeft="10dip"/>
</LinearLayout>

和其他名为 homepage 的布局文件看起来像:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true">
    <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:background="#ffffff">
        <include layout="@layout/companylogo"  />
   </RelativeLayout>
</ScrollView>

但这不会将图像添加到homepage 布局。

我什至尝试添加android:layoutwidth/height 标签。不知道我在哪里犯了错误。

提前致谢。

【问题讨论】:

  • 发布您的homepage 布局
  • 如果有名字投票,+1,:) :) :)
  • @vokilam:我已经更新了问题。
  • 你测试的是哪个安卓版本?
  • 实际上,您的布局适用于 2.2、2.3 和 4.0(已测试)。检查你的drawable。尝试使用此布局制作新的空项目

标签: java android include


【解决方案1】:

实际上,当我们在代码中实现 xml 时,为了显示布局的效果,我们必须多次清理项目。

并尝试将 layout_width 和 layout_height 属性都添加到包含标签中。

尝试清理项目,如果仍然无法正常工作,那么

关闭 Eclipse,然后再次打开它,就可以了。

欲了解更多信息,请查看此链接:

android include tag - invalid layout reference

Does Android XML Layout's 'include' Tag Really Work?

【讨论】:

    【解决方案2】:

    现在再试一次:

    <include layout="@layout/companylogo"  
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多