0
J'essaie de récupérer un RotateDrawable défini en XML mais il provoque une exception lorsque j'appelle getDrawable(). Voici mes fichiers XML et Java:Obtenir un RotateDrawable à partir de XML provoque un plantage
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 (uniquement le code correspondant indiqué)
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);
}
Quelqu'un peut-il Dites-moi comment je suis censé obtenir un RotateDrawable de XML?