gpt4 book ai didi

android - 引用另一个 XML 文件中的 View

转载 作者:太空狗 更新时间:2023-10-29 14:32:07 24 4
gpt4 key购买 nike

我在名为 a.xml 的文件中有一个 ListView。

<ListView
android:id="@+id/mylistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scrollbars="none"
android:layout_above="XYZ"
/>

在 a.xml 中,我还包含另一个名为 b.xml 的文件。

<include android:id="@+id/bottombar" layout="@layout/b" />

对于ListView的其中一个设置,我想引用一个存在于b.xml中的id(XYZ)。

我有办法做到这一点吗?

我试过以下方法:

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="@+id/bottombar" layout="@layout/b" />
<ListView
android:id="@+id/mylistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scrollbars="none"
android:layout_above="@id/bottombar_background"
/>
</RelativeLayout>

@layout/b 中存在 @id/bottombar_background,但 Eclipse 向我抛出“无资源”错误。

最佳答案

使用完 setContentView(R.layout.a) 后,您应该可以使用 findViewById(R.id.my_id_in_b)

关于android - 引用另一个 XML 文件中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5637382/

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