gpt4 book ai didi

java - 在android编程中使用

转载 作者:行者123 更新时间:2023-11-30 02:25:38 25 4
gpt4 key购买 nike

我正在制作一个应用程序,我有以下 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 的按钮,它只想在整个页面上查看可展开的 ListView 。我所做的是创建一个新的 XML 文件,并添加以下包含语句:

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

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

1 - 没有布局 ID

2- 我只想要列表,而不是按钮和我要放入原始布局中的所有其他内容。将要发生的事情是,如果我向列表中添加一些内容,我需要能够查看它而无需选择向其添加 antthing。

因此我的问题是:

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

最佳答案

包含应该说:

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

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

但我真的不明白为什么要在这里使用 include 如果您不想重新使用整个布局,而只是其中的列表部分。 include 的存在可以轻松地在其他布局中使用布局,如果您只需要一个 ListView,则只需使用一个 ListView

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

关于java - 在android编程中使用<include/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27931459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com