Reputation: 1115
I am offsetting an imageview on Action_MOVE, by calling offsetTopandBottom(int distanceY) and also invalidating after every call.
But the frames are visible, while dragging the view on Froyo and Gingerbread. Any suggestion ?
/**
* Called on ACTION_MOVE
**/
private void offsetView(View view, int distanceY) {
view.offsetTopAndBottom(distanceY);
view.invalidate();
view.invalidateDrawable(view.getBackground());
}
I also tried posting on each offsetCall, but it didn't work.
post(new Runnable() {
@Override
public void run() {
view.offsetTopAndBottom(distanceY);
view.invalidateDrawable(getBackground());
view.invalidate();
}
});
Should I do a postDelayed for redraw, or should I post delay the call to offsetTopAndBottom(int offset) ?
SOLVED:
Execute drawing and offset calls separately 10ms (or some other time <60ms) apart.
view.offsetTopAndBottom(distanceY);
postDelayed(new Runnable() {
@Override
public void run() {
view.invalidateDrawable(getBackground());
view.invalidate();
}
}, 10);
Thanks Greg :)
Upvotes: 0
Views: 88
Reputation: 15379
Hardware acceleration is not enabled by default prior to Android 3.1.
Add android:hardwareAccelerated="true"
to your manifest, either for the activity or the application.
UPDATE: If that doesnt work, I think Android delays the redraw until your UI thread goes idle, but in your case it does not ever go idle because you are constantly handling touch events. So you should try posting to a handler instead of drawing immediately, to give the OS a chance to redraw.
Try this:
Handler h = new Handler();
private void offsetView(View view, int distanceY) {
h.post(new Runnable() {
@Override
public void run() {
view.offsetTopAndBottom(distanceY);
view.invalidate();
view.invalidateDrawable(view.getBackground());
}
});
}
Upvotes: 2