【发布时间】:2010-12-16 13:49:40
【问题描述】:
我在 Android 库项目中有一个自定义 PieTimer 视图
package com.mysite.android.library.pietimer;
public class PieTimerView extends View {
...
我还有一个在我的 PieTimer 中使用的 XML 属性文件
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.PieTimerView);
XML 样式文件如下所示
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="PieTimerView">
<attr name="max_size" format="dimension" />
<attr name="start_angle" format="string" />
<attr name="start_arc" format="string" />
<attr name="ok_color" format="color" />
<attr name="warning_color" format="color" />
<attr name="critical_color" format="color" />
<attr name="background_color" format="color" />
</declare-styleable>
</resources>
我在一个使用该库的项目的布局文件中有 PieTimer,就像这样
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root" android:layout_gravity="center_horizontal"
xmlns:app="http://schemas.android.com/apk/res/com.mysite.android.library.myapp"
xmlns:pie="com.mysite.library.pietimer"
>
<com.mysite.library.pietimer.PieTimerView
pie:start_angle="270"
pie:start_arc="0"
pie:max_size="70dp"
pie:ok_color="#9798AD"
pie:warning_color="#696DC1"
pie:critical_color="#E75757"
pie:background_color="#D3D6FF"
android:visibility="visible"
android:layout_height="wrap_content" android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_alignParentRight="true">
</com.mysite.library.pietimer.PieTimerView>
以前我使用xmlns:app 作为app:ok_color 等属性的命名空间,但是当我将我的项目设为库项目并有一个实现该库的免费和完整版本时,我发现它不再有效,所以我添加了饼命名空间。
PieTimerView 显示,但属性不起作用,它们使用默认值(以前没有发生过),因此这里发生了一些命名空间冲突。
这样做的正确方法是什么?
【问题讨论】:
-
您找到更好的解决方案了吗?
-
请告诉我有更好的方法来做到这一点。我在图书馆项目中包含 admob 广告时遇到了同样的问题。
-
好问题。我也面临同样的问题。欢迎大家提出意见。
-
@SIVAKUMAR.J - JRaymond 对此给出了正确答案(在我撰写此评论时,这是该问题的最高评分。)
标签: android