gpt4 book ai didi

android - 具有目标布局的自定义 View 属性的 ViewStub

转载 作者:太空狗 更新时间:2023-10-29 13:43:18 28 4
gpt4 key购买 nike

是否可以通过 ViewStub 将自定义属性传递到目标布局的根元素?像这样:

<ViewStub
android:layout="@layout/custom_view"
app:customAttr="12345"
/>

custom_view.xml 在哪里:

<blah.CustomView ...>
...
</blah.CustomView>

当我尝试这样做时,CustomView.java 没有在 AttributeSet 中获取“app:customAttr”。

当我直接使用 CustomView,没有 ViewStub 时

<blah.Custom app:customAttr="12345"/>

属性成功进入AttributeSet。

但它不再懒惰了。

有什么解决办法吗?

谢谢,尤里。

最佳答案

<include> ViewStub 允许您覆盖的唯一属性是布局属性以及 subview 在膨胀后将具有的 ID。

关于android - 具有目标布局的自定义 View 属性的 ViewStub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3109843/

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