我在Android库项目中有一个自定义的PieTimer视图
package com.mysite.android.library.pietimer;
public class PieTimerView extends View {
...
Run Code Online (Sandbox Code Playgroud)
我还有一个XML属性文件,我在PieTimer中使用它
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.PieTimerView);
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我在一个布局文件中有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>
Run Code Online (Sandbox Code Playgroud)
以前我用的xmlns:app是属性的命名空间, …
这一切都在标题中.虽然我看到<uses-sdk>在我见过的所有示例库项目中都有指定AndroidManifest.xml,但我觉得它是无关紧要的.
事实上,我怀疑<uses-permission>也是无关紧要的,因为都是的属性<manifest>,比其他package.
谁能确认一下?
我读到了http://schemas.android.com/apk/res-auto "命名空间问题,这些问题最终在aapt工具的第17版中得到了解决.除了自定义视图可能有属性之外,我不明白为什么要使用CustomView添加为.jar文件时不能使用自定义属性?它只适用于库项目.为什么?
有一些Android项目由于这个问题总是手动添加视图,但为什么运行时似乎无法实例化这些组件?似乎有有效的构造函数(Context context,AttributeSet attrs),如com.jjoe64.graphview.BarGraphView
谁能让我更清楚?