Android resize View not smooth

M

MaMiFreak

Guest
I have a custom ImageView and a Button, clicking the Button and moving up and down resizes the ImageView but it does not run smoothly.

I created a separate thread to smoothen the user movement but apparently it can't make any GUI changes.. I tried to find a way to use Animation but i don't see a way to continuously update the target height.

Working code
Button onTouchListener:

// resize button start location
private PointF startResize = new PointF();

ImageView resize = (ImageView) findViewById( R.id.resize );
resize.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:

// save first touch location
startResize.set( boardImage.getHeight(), event.getY() );
break;
case MotionEvent.ACTION_MOVE:

// calculate horizontal move distance
int movedDistance = Math.round(event.getY() - startResize.y);

if ( Math.abs( movedDistance ) > 4 ) {

// set new height
boardImage.setHeight( movedDistance + (int)startResize.x );
}

break;
}
return true; // indicate event was handled
}
});


Custom ImageView
setHeight:

// set height and revalidate
public void setHeight( int newHeight ){

height = newHeight;

// rescale image
setImageMatrix( checkMatrix() );

requestLayout();
}


onMeasure:

@Override
public void onMeasure( int widthMeasureSpec, int heightMeasureSpec ) {

setMeasuredDimension( width, height );
}


EDIT better explanation

Touching the red encircled Button and dragging it up/down resizes the ImageView above it to any given size. see images below.

I tried to use an Animation but i have to cancel it and set a new one with every tiny little movement made witch results in creating 20/30 new Animations every second..

zoomed layout
(source: eightytwo.axc.nl)

layout
(source: eightytwo.axc.nl)

Continue reading...
 
Top