我在创建使用XML简单的圆角矩形的麻烦。每次我尝试的角落元素添加到自定义形状,我得到:
I'm having trouble creating a simple rounded rectangle using XML. Every time I try to add the "corners" element to the custom shape I get:
java.lang.UnsupportedOperationException 在 android.graphics.Path.addRoundRect(Path.java:514) 在 android.graphics.drawable.GradientDrawable.draw(GradientDrawable.java:314) 在 android.view.View.draw(View.java:6520) ......
java.lang.UnsupportedOperationException at android.graphics.Path.addRoundRect(Path.java:514) at android.graphics.drawable.GradientDrawable.draw(GradientDrawable.java:314) at android.view.View.draw(View.java:6520) ...
RES / dawable / rounded_rectangle.xml:
res/dawable/rounded_rectangle.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffffff"/>
<stroke android:width="3dp"
android:color="#ff000000"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
使用上述形状简单layout.xml:
simple layout.xml using the above shape:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<View android:id="@+id/View01"
android:background="@drawable/rounded_rectangle"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</View>
</RelativeLayout>
据透露,我试图编译为Android 2.1,我已经安装到Eclipse所有最新的更新和Android SDK。这种形状的东西,我看到了在其他网站上直接拷贝,但由于某种原因它不想为我工作。
Fyi, I'm trying to compile for Android 2.1 and I have all the latest updates installed to Eclipse and the Android SDK. This shape is a direct copy of something I saw on another website, but for some reason It doesn't want to work for me.
感谢。
所以,我只是在摆弄这一点,我换了几行,在rounded_rectangle.xml得到它的工作。请看下图:
So, I was just playing around with this a bit and I changed a couple of lines in the rounded_rectangle.xml to get it working. See below:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffffff"/>
<stroke android:width="3dp"
android:color="#ff000000"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<corners android:radius="30dp"/>
</shape>
我只希望谷歌将推出一个适当的参考文档,用于创建基于XML的形状。几个小时后(4+)追捕的例子在网络上的,我觉得它仍然是一个猜谜游戏,什么元素/属性在这些类型的XML文档的支持。很抱歉的小咆哮。
I only wish Google would put out a proper reference doc for creating XML-based shapes. After hours (4+) of hunting down examples on the Web, I feel like it's still a guessing game as to what elements/attributes are supported in these types of XML documents. Sorry for the mini-rant.
我希望这可以帮助别人。
I hope this helps someone else.