I have a layout (which extends a framelayout) with a gridview and an imageview. I scroll through the layout with an onTouchListener,. In my Galaxy Nexus it works fine, but in AVD and other devices (Galaxy SII for example) the view shakes and I can't find out why.
XML
<paricio.toni.caththemole.MyFrameLayout
android:id="@+id/campo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/zonaMarcador" >
<ImageView
android:id="@+id/fondo"
android:layout_width="800dp"
android:layout_height="800dp"
android:contentDescription="@android:string/untitled"
android:src="@drawable/terrenoarena" />
<GridView
android:id="@+id/gridView1"
android:layout_width="640dp"
android:layout_height="640dp"
android:layout_gravity="center"
android:clickable="true"
android:columnWidth="80dp"
android:horizontalSpacing="0dp"
android:numColumns="8"
android:overScrollMode="never"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:verticalSpacing="0dp" >
</GridView>
And setOnTouchListener code:
gridview.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int desplazamiento[]={0,0};
campo.getLocationOnScreen(desplazamiento);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mx = event.getX();
my = event.getY();
return false;
case MotionEvent.ACTION_MOVE:
curX = event.getX();
curY = event.getY();
campo.scrollBy((int) (mx - curX), (int) (my - curY));
mx = curX;
my = curY;
return false;
case MotionEvent.ACTION_UP:
curX = event.getX();
curY = event.getY();
campo.scrollBy((int) (mx - curX), (int) (my - curY));
return false;
}
return false;
}
});
MyFrameLayout is a FrameLayout extended to be bigger than the screen:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(0, 0);
}
I can scroll an ImageView in AVD without shake, but if I move the image and gridview (instead of the frame) the views move differently (and wrong). I have tried many things but I can't avoid the shake. ¿Any idea?
Thanks.