我正在开发一个从 RelativeLayout 扩展的子类,并且有一个OnScaleGestureListener
. 我希望当您在视图上缩放时,这种变化的高度(就像缩放一样,但是调整对象的大小)。但它给我一个例外,我不知道我该如何解释它。
我的代码是:
public class simpleOnScaleGestureListener extends SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
tmpScale = detector.getCurrentSpan() / detector.getPreviousSpan();
Log.d("DEBUG", ".getCurrentSpan() is "+detector.getCurrentSpan());
Log.d("DEBUG", ".getPreviousSpan() is "+detector.getPreviousSpan());
Log.d("DEBUG", ".getScaleFactor() is "+detector.getScaleFactor());
scaling = true;
RelativeLayout.LayoutParams params = new LayoutParams(kTicketWidth, (int) (getMeasuredHeight()*mScaleFactor));
setLayoutParams(params);
//invalidate();
requestLayout();
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
mScaleFactor = detector.getCurrentSpan() / detector.getPreviousSpan();
adjustTickets();
//Expand Animation
/*if (mScaleFactor >= kMinScale){
ScaleAnimation anim = new ScaleAnimation(1, 1, mScaleFactor, 1);
startAnimation(anim);
tmpScale=1;
adjustTickets();
} else if (mScaleFactor < kMinScale){
ScaleAnimation anim = new ScaleAnimation(1, 1, mScaleFactor, 1);
startAnimation(anim);
tmpScale = kMinScale;
adjustTickets();
}
scaling = false;*/
Log.d("SCALE", "Scale have ended");
}
}
另外,我需要的例外是:
05-19 13:10:28.943: E/AndroidRuntime(15701): FATAL EXCEPTION: main
05-19 13:10:28.943: E/AndroidRuntime(15701): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
05-19 13:10:28.943: E/AndroidRuntime(15701): at android.widget.LinearLayout.measureVertical(LinearLayout.java:655)
05-19 13:10:28.943: E/AndroidRuntime(15701): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
05-19 13:10:28.943: E/AndroidRuntime(15701): at android.view.View.measure(View.java:15190)
我不知道为什么会发生的另一件事是 mScaleFactor 不断更改为 1.0,当它更改为 0.81464 或 1.28774 时,它又更改为 1.0。有谁知道为什么会这样?