【问题标题】:Access Widget Attribute Through AttributeSet - Android通过 AttributeSet 访问 Widget 属性 - Android
【发布时间】:2011-04-26 02:30:50
【问题描述】:

这应该是相当简单的任务。我有以下看法:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:panel="org.miscwidgets"

<org.miscwidgets.widget.Panel
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="right"
    panel:handle="@+id/panelHandle"
    panel:content="@+id/panelContent"
    panel:position="right">

我正在尝试访问视图构造函数中的位置属性,但它始终返回 null。

        String posVal = attrs.getAttributeValue("schemas.android.com/apk/gen/org.miscwidgets", "position");

如何获得价值?我的命名空间错了吗?

我看到了对 Styleables 的引用,但我没有找到任何未被弃用的内容。

【问题讨论】:

    标签: java android view namespaces


    【解决方案1】:

    我认为你应该写在你的 xml 中

    xmlns:panel="http://schemas.android.com/apk/gen/org.miscwidgets"
    

    代替

    xmlns:panel="org.miscwidgets"
    

    然后得到它

    attrs.getAttributeValue("http://schemas.android.com/apk/gen/org.miscwidgets", "position");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-28
      • 2012-02-04
      • 2019-09-13
      • 1970-01-01
      相关资源
      最近更新 更多