【问题标题】:using the <include/> in android programming在android编程中使用<include/>
【发布时间】:2015-03-11 23:00:49
【问题描述】:

我正在制作一个应用程序,我有以下 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#f4f4f4" >

            <ExpandableListView
                android:id="@+id/lvExp"
                android:layout_width="match_parent"
                android:layout_height="325dp" />

            <Button
                android:id="@+id/add_claim"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Add Claim" />
    </LinearLayout>

我制作了一个名为 View_list 的按钮,它只想查看整个页面上的可展开列表视图。我所做的是创建一个新的 XML 文件,并添加了以下包含语句:

 <include android:id="@+id/lvExp"
         android:layout_width="match_parent"
         android:layout_height="match_parent"/>

但是,我意识到这现在可以工作有两个原因

1 - 没有布局 ID

2- 我只想要列表,而不是按钮和我要放入原始布局的所有其他内容。将会发生的情况是,如果我在列表中添加了一些东西,我需要能够在没有添加 antthing 选项的情况下查看它。

因此我的问题是这样的:

如何找到布局 ID,如何防止整个布局显示,只显示列表。我真的很感激一些建议。

【问题讨论】:

    标签: java android include


    【解决方案1】:

    包含应该说:

     <include layout="@layout/View_list" 
             android:id="@+id/lvExp"
             android:layout_width="match_parent"
             android:layout_height="match_parent"/>
    

    这包括另一个布局中的View_list.xml 布局。

    但我真的不明白如果您不想重用整个布局,而只想重用它的列表部分,为什么要在这里使用includeincludes 的存在是为了在其他布局中轻松使用布局,如果您只需要 ListView,请使用 ListView

    编辑:我不确定你的问题是否正确,但我不会删除答案,因为你对此发表了评论。 如果您想在单击按钮时隐藏按钮或其他视图,您可以通过编程将其可见性设置为消失。

    【讨论】:

    • 感谢您提供的信息。你会如何建议我只使用列表呢?我明白你在说什么,但我不知道该怎么做。有什么建议吗?
    • 把列表本身就是一个布局文件。然后列表在每个你想要的地方。
    • 谢谢。这很有意义。
    猜你喜欢
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 2013-06-30
    • 2011-04-25
    • 2022-01-25
    • 2017-10-11
    • 1970-01-01
    相关资源
    最近更新 更多