Reputation: 762
I'm working on a subClass that extends from RelativeLayout, and have a OnScaleGestureListener
. I want that when you scale on the view, the height of this change(it's like scalaing, but resizing the object). But it takes me an exception that I don't know how can I interprete it.
My code is:
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");
}
}
Also the exception that it takes to me is:
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)
And another thing that I don't know why it happens is that mScaleFactor changes to 1.0 constantly, when it changes to 0.81464 or 1.28774 then it changes again to 1.0. Does anyone knows why this happens?
Upvotes: 0
Views: 385
Reputation: 10395
exception shows what's the problem
android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
you are trying to cast a LinearLayout to RelativeLayout , check your XML file
Upvotes: 2