【问题标题】:how to call one xml design into another xml design with using inflater in android如何在android中使用inflater将一个xml设计调用到另一个xml设计中
【发布时间】:2012-12-16 13:37:15
【问题描述】:

这在 android 中是否可行?

我有一个xml design1 文件这个文件我想添加另一个xml design2..(即)

第一个xml 是第二个xml design2 中的一部分

【问题讨论】:

  • include 是关键字.. here
  • 感谢所有对这个问题提出建议的人。这对我很有用..再次非常感谢,祝大家新年快乐

标签: android xml android-layout android-widget


【解决方案1】:

要在另一个xml 文件中包含xml,您应该使用include 关键字

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

要以编程方式包含xml 文件,您可以使用LayoutInflater

【讨论】:

  • 感谢所有对这个问题提出建议的人。这对我很有用..再次非常感谢,祝大家新年快乐
【解决方案2】:

它很容易在 xml 中使用标签并使用布局属性,它对你很有用

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

【讨论】:

  • ..并将另一个包裹在&lt;merge&gt;中,可以节省一些资源。
【解决方案3】:

你可以这样做,是的。通常您只想对动态内容执行此操作,例如 ListView 或 GridView 中的列表项。

如果您只想在多个活动布局中重复使用静态内容,您可能希望在布局中使用“包含”标签。

【讨论】:

    【解决方案4】:

    请在您的 xml 中包含布局

    <include
        android:id="@+id/" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        layout="@layout/viewgroup_bottom_bar" /> // please set proper layout name in your layout folder
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多