从XML获取RotateDrawable会导致崩溃

时间:2011-05-02 10:41:58

标签: android

我正在尝试检索以XML格式定义的RotateDrawable,但是当我调用getDrawable()时它会导致异常。这是我的XML和java文件:

square.xml

    <?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" 
    android:id="@+id/mysquare">
    <solid android:color="#0000f8"/>
    <size android:height="200dp" android:width="200dp"></size>
    <padding android:top="0dp"></padding>
</shape>

myrotate.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://android.com/apk/res/android" 
        android:drawable="@drawable/square"
        android:fromDegrees="0"
        android:toDegrees="45"
        android:pivotX="50%"
        android:pivotY="50%">>
        </rotate>

Indicator.java(仅显示相关代码)

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    setContentView(R.layout.drawablelayout);
    Button b = (Button)findViewById(R.id.btnAnimate);
    b.setOnClickListener(this);
    r = getResources();

    /* this is where the exception happens */
    RotateDrawable rt = (RotateDrawable) r.getDrawable(R.drawable.myrotate);


}

有谁能告诉我我应该如何从XML获得RotateDrawable?

1 个答案:

答案 0 :(得分:1)

您在myrotate.xml

底部的第2行还有一个>
android:pivotY="50%">>

删除它。