中的屬性我有一個自定義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