Hi,
We have defined a layout programmatically as below:
framelayout1 = new FrameLayout(this);
FrameLayout.LayoutParams r1 = new
FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
framelayout1.setLayoutParams(r1);
scrollview = new ScrollView(this);
scrollview.setFillViewport(true);
FrameLayout.LayoutParams r3 = new
FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
//FrameLayout.LayoutParams r3 = new
FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
scrollview.setLayoutParams(r3);
framelayout1.addView(scrollview);
hscrollview = new HorizontalScrollView(this);
hscrollview.setFillViewport(true);
//RelativeLayout.LayoutParams r4 = new
RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
FrameLayout.LayoutParams r4 = new
FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
hscrollview.setLayoutParams(r4);
hscrollview.setPadding(0, 0, 0, 10);
scrollview.addView(hscrollview);
framelayout2 = new FrameLayout(this);
FrameLayout.LayoutParams r5 = new
FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,Gravity.NO_GRAVITY);
framelayout2.setLayoutParams(r5);
hscrollview.addView(framelayout2);
view = new ImageView (this);
view.setScaleType(ScaleType.FIT_XY);
bitmap =
BitmapFactory.decodeResource(getResources(),R.drawable.texture);
width = screenwidth;
height = width;
widthinitial=width;
heightinitial=height;
FrameLayout.LayoutParams r6 = new
FrameLayout.LayoutParams(width,height,Gravity.NO_GRAVITY);
view.setLayoutParams(r6);
view.setImageBitmap(bitmap);
view.requestLayout();
framelayout2.addView(view);
setContentView(framelayout1);
We are pinch zooming the imageview on Touch events as below:
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
try
{
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: //first finger down
only
start.set(event.getX(), event.getY());
end.set(event.getX(), event.getY());
break;
case MotionEvent.ACTION_POINTER_DOWN: //second
finger down
oldDist = spacing(event);
mode = ZOOM;
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_MOVE:
if (mode == ZOOM)
{
newDist = spacing(event);
if (zoom==true)
{
scale = newDist / oldDist; //thinking
i need to play
around with this value to limit it
if ((scale>1.01)||(scale<0.99))
{
scalefinal= scale*scalecurrent;
if (scalefinal<1)
{
scalefinal=1;
}
else if (scalefinal>6)
{
scalefinal =6;
}
scalecurrent=scalefinal;
width = (int)
(widthinitial*scalefinal);
height = (int)
(heightinitial*scalefinal);
marginleft =
(int)(screenwidth-width)/2;
margintop = (int)
(screenheight-height)/2;
if (margintop<0)
margintop=0;
FrameLayout.LayoutParams r6 = new
FrameLayout.LayoutParams(width,height,Gravity.NO_GRAVITY);
view.setLayoutParams(r6);
view.requestLayout();
scrollview.setPadding(0,
margintop, 0, 0);
scrollview.post(new
Runnable() {
public void run() {
if
(height>screenheight)
{
scrollview.scrollTo(0, (int) (height-
screenheight)/2);
}
}
});
hscrollview.post(new
Runnable(){
public void run() {
if (width>screenwidth)
{
hscrollview.scrollTo((int)(width-screenwidth)/2,
0);
}
}
});
}
}
}
oldDist = newDist;
zoom=true;
}
break;
case MotionEvent.ACTION_POINTER_UP:
zoom=false;
v.getParent().requestDisallowInterceptTouchEvent(false);
mode=NONE;
break;
case MotionEvent.ACTION_UP:
mode=NONE;
break;
}
}
catch (Exception ex)
{
int i=0;
i++;
}
return true;
}
We find the application crashing on Pinch and Zoom every now and then
with ArrayIndexOutOfBounds exception and the error doesn't get caught
with the try catch in OnTouch. What could be the problem and how do we
solve this problem?
Thank you,
B.Arunkumar
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en