XML布局文件中有一个GlowPadView问题。
我的布局代码是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:glowpad="http://schemas.android.com/apk/com.fima.glowpadview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.fima.glowpadview.GlowPadView
android:id="@+id/glow_pad_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical"
android:layout_marginBottom="@dimen/glowpadview_margin_bottom"
android:focusable="true"
android:gravity="center"
glowpad:directionDescriptions="@array/snooze_dismiss_direction_descriptions"
glowpad:feedbackCount="1"
glowpad:glowRadius="@dimen/glowpadview_glow_radius"
glowpad:handleDrawable="@drawable/ic_alarm_alert_touch_handle"
glowpad:innerRadius="@dimen/glowpadview_inner_radius"
glowpad:outerRadius="@dimen/glowpadview_target_placement_radius"
glowpad:outerRingDrawable="@drawable/ic_alarm_alert_outerring"
glowpad:pointDrawable="@drawable/ic_lockscreen_glowdot"
glowpad:snapMargin="@dimen/glowpadview_snap_margin"
glowpad:targetDescriptions="@array/snooze_dismiss_descriptions"
glowpad:targetDrawables="@array/snooze_dismiss_drawables"
glowpad:vibrationDuration="20" />
我得到以下错误:
The following classes could not be instantiated:
- com.fima.glowpadview.GlowPadView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
java.lang.IllegalStateException: Must specify at least one target drawable
at com.fima.glowpadview.GlowPadView.<init>(GlowPadView.java:247)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0( at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:442)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:194)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:206)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:131)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:756)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:728)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:373)
我该如何解决?
最佳答案
有一个属性是:glowpad:targetDrawables
导致此问题,除了提供至少一个有效的目标drawable之外,还必须定义此属性。
正如我看到的,您已经定义了它:glowpad:targetDrawables="@array/snooze_dismiss_drawables"
,所以问题出在文件snooze_dismiss_drawables
中,我相信它肯定包含了如下所有空值:
<array name="snooze_dismiss_drawables">
<item>@null</item>
<item>@null</item>
<item>@null</item>
<item>@null</item>
</array>
因此,要使一切正常工作,请在四个方向中的任何一个方向上至少定义一个有效的Drawable,以便GlowPad正常工作,如果您希望它没有可见的Drawles,则可以定义一个透明的Drawable,它也将正常工作,例如:
<array name="snooze_dismiss_drawables">
<item>@android:color/transparent</item>
<item>@null</item>
<item>@android:color/transparent</item>
<item>@null</item>
</array>