中的属性我有一个自定义PieTimer查看在Android库项目帮助与自定义视图中的Android库项目
package com.mysite.android.library.pietimer;
public class PieTimerView extends View {
...
我也有一个XML属性,这是我在我的PieTimer使用文件
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显示但属性不起作用,它们使用默认值(这在之前没有出现),所以这里有一些名称空间冲突。
这样做的正确方法是什么?
您是否找到更好的解决方案? – 2011-01-25 15:26:12
请告诉我有更好的方法来做到这一点。在包含图书馆项目中的admob广告时,我遇到同样的问题。 – 2011-02-13 23:45:39
好问题。我也面临同样的问题。欢迎大家给点意见。 – 2012-09-25 07:20:46