【问题标题】:What's tools:layout in fragment xml file?什么是工具:片段 xml 文件中的布局?
【发布时间】:2013-10-08 19:00:39
【问题描述】:

我使用 ADT Eclipse 启动了一个基于主/详细流模板的新 Android 应用程序。该模板创建了两个活动,一个主片段和一个细节片段,以适应大小屏幕。

我注意到activity_item_list.xml 文件具有tools:layout 属性:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/item_list"
    android:name="com.example.fragmenttwopanel.ItemListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    tools:context=".ItemListActivity"
    tools:layout="@android:layout/list_content" />

我尝试删除该属性,应用程序以相同的方式运行,但在 ADT 的图形布局选项卡中,一条消息询问我:

从“片段布局”上下文菜单中选择预览布局

它的目的是什么?只是为了在图形布局中预览?

【问题讨论】:

标签: android xml android-layout graphical-layout-editor


【解决方案1】:

这是 IDE 工具使用的命名空间。这不是在设备(或模拟器)上运行应用程序所必需的。另一方面,如果您离开它们,Android 将在应用程序在设备上运行时忽略它们。

这被例如使用。 lint 和图形布局选项卡。

您可以在此处查看 lint 如何使用它:http://developer.android.com/tools/debugging/improving-w-lint.html 在 XML 中配置 lint 检查部分。

【讨论】:

    【解决方案2】:

    是的,这只是图形布局编辑器应该如何在编辑器中显示片段的信息。

    通常tools 属性(带有tools 命名空间前缀,用xmlns:tools="http://schemas.android.com/tools" 声明)由开发工具使用,而不是在应用程序本身中编译。

    【讨论】:

      【解决方案3】:

      右击灰色区域,“片段布局->选择布局”并选择你的布局,完成!

      【讨论】:

        猜你喜欢
        • 2012-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-11
        • 2016-12-16
        • 1970-01-01
        • 2013-01-10
        • 1970-01-01
        相关资源
        最近更新 更多