【问题标题】:Android: How to use tools with include layoutAndroid:如何使用包含布局的工具
【发布时间】:2014-05-29 21:18:30
【问题描述】:

我如何使用工具:

xmlns:tools="http://schemas.android.com/tools"

<include>?

我有一个布局A,我使用工具用测试数据填充所有文本字段。我有布局 B 使用 include 将布局 A 复制到其中。但是当我这样做时,我看不到A 的测试数据。

如何查看B中包含的A的测试数据?

*两个布局都有xmlns:tools="http://schemas.android.com/tools,我什至把它推到布局标签。

【问题讨论】:

    标签: android xml android-layout android-tools-namespace


    【解决方案1】:

    检查此链接,Android tools attributes。它应该让您了解如何使用工具属性。 具体看tools:showIn属性。它基本上允许您在 layout_B 中渲染 layout_A,其中 layout_B 在 xml 中的某处有<include layout="@layout/layout_A"/>

    这是一个例子:

    layout_A

    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:showIn="@layout/layout_B"
        >
    
    <!-- Your layout code goes here -->
    
    </RelativeLayout>
    

    layout_B

    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    
    <include layout="@layout/layout_A"/>
    
    <!-- Your layout code goes here -->
    
    </RelativeLayout>
    

    【讨论】:

    • 是的。我从我正在处理的项目中提取了这段代码。我只是更改了布局的名称。你能发布你的代码吗?
    • 链接失效
    【解决方案2】:

    layout_widthlayout_height添加到include标签中,否则你会发现很难在RelativeLayout中排列

    【讨论】:

      猜你喜欢
      • 2018-01-12
      • 2021-04-10
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多