【发布时间】:2011-01-11 19:29:18
【问题描述】:
我正在尝试实现一个自定义视图,我希望能够通过 XML 布局文件为其传递参数。问题是这些参数或多或少是任意的;它们最终将被用作构造 URL 的参数(构建和维护有效参数的完整列表是不值得的)。
因此,ApiDemos 示例代码中的方法不一定合适,因为我不知道参数的名称。
我尝试做的事情如下:
public Chart(Context context, AttributeSet attributes) {
super(context, attributes);
params = new HashMap<String, String>();
for(int i = 0; i < attributes.getAttributeCount(); i++)
params.put(attributes.getAttributeName(i), attributes.getAttributeValue(i));
}
这可能不是解决这个问题的最佳方法.. 但我遇到的主要问题是如何过滤掉 android: 属性(即我不希望 android:layout_height 等出现在参数中) ?
【问题讨论】:
标签: android android-widget android-layout