0
我定義了一個擴展類View的自定義視圖。Android矩陣運算拋出IllegalStateException
public class MyView extends View{
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
Matrix m= new Matrix();
//this line is ok
m.setScale(...);
}
public boolean onTouchEvent(MotionEvent event){
//this same operation throws "IllegalStateException: Matrix can not be modified"
m.setScale(...);
}
}
我想知道爲什麼我得到這樣的例外。我搜索了網頁,但根本沒有發現任何線索。
我這樣做,但不工作。感謝提示 – wizoleliam
發佈您的錯誤'LogCat'。 –
我找到了原因。這是我的不好。我以爲我使用m = new Matrix()來初始化我的矩陣;但實際上是「m = getMatrix()」。對於那個很抱歉。看起來這個視圖的矩陣是不可變的。這就是我得到異常的原因? – wizoleliam