【问题标题】:ViewStub with custom View attributes for target layout具有用于目标布局的自定义视图属性的 ViewStub
【发布时间】:2011-03-07 19:03:27
【问题描述】:

是否可以通过 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 ok。

但它不再懒惰了。

有什么解决办法吗?

谢谢, 尤里。

【问题讨论】:

    标签: android custom-attributes viewstub


    【解决方案1】:

    像&lt;include&gt; 一样,ViewStub 允许您覆盖的唯一属性是布局属性以及子视图在膨胀后将具有的 id。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      相关资源
      最近更新 更多