我一直在尝试导入形状xml到自定义视图。这样,如何将形状资源(xml)导入代码?
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid
android:color="#f0600000"/>
<stroke
android:width="10dp"
android:color="#00FF00"/>
<corners
android:radius="15dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
,并在我的自定义视图代码中,我试图从我的外部资源
private void initTestView(){
Resources res = this.getResources();
mDrawable = (ShapeDrawable)res.getDrawable(R.drawable.recshape);
}
但如果这ruuning的模拟器,它叫错误,因为mDrawable应该叫它是“GradidentDrawable”。但是没有意义的是上面的xml代码仅适用于“ShapeDrawable”。 我不明白为什么会发生,有人知道它为什么会发生?
这可能只是一个复制/粘贴错误,但你永远不会关闭你的形状。实际文件末尾是否有? – CaseyB 2010-06-18 03:27:22
这是我的错,而复制/粘贴,谢谢! – tomahawk28 2010-06-20 00:36:48