1
我需要訪問ClipDrawable
來設置剪輯級別。這裏是繪製:ClipDrawable getDrawable()返回一個StateListDrawable
@drawable/left_arrow
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<clip
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/rotated_square"
android:clipOrientation="horizontal"
android:gravity="left" />
</item>
</selector>
@drawable/rotated_square
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="45">
<shape
android:shape="rectangle">
<size
android:width="250dp"
android:height="250dp"/>
<solid
android:color="#ffffff"/>
</shape>
</rotate>
</item>
</selector>
當我嘗試檢索繪製left_arrow
作爲ClipDrawable
這樣的:
ClipDrawable drawable = (ClipDrawable) getResources().getDrawable(R.drawable.left_arrow);
我得到以下錯誤我ñlogcat的:
Caused by: java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.ClipDrawable
at com.vcapra1.pingpongscoreboard.MainActivity.onCreate(MainActivity.java:89)
爲什麼我ClipDrawable
返回作爲StateListDrawable?
它的確是一個statelistdrawable,其第一個元素是「你的drawable」 – rupps