I've looked over the other questions about this and none apply to my situation. my onDraw method in a custom view is called constantly, about once ever .3 seconds.
I have a custom view, that draws a map of the inside of a building. The view is larger than the view area so I've wrapped the custom view inside a custom ScrollView and HorizontalScrollView. The onDraw method is large, so I can't post it here. However I have removed all code from onDraw and it did not change anything.
If I remove the use of the two scrolling views, onDraw is called once only and is only ever called again if I pinch zoom the map.
Edit: added in the full custom scroll class. the vertical scroll class is the same as this.
public class SCEHorizontalScrollViewBase extends HorizontalScrollView {
private GestureDetector mGestureDetector;
private String TAG = this.getClass().getName();
public SCEHorizontalScrollViewBase(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, new XScrollDetector());
setFadingEdgeLength(10);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.d(TAG, "onInterceptTouchEvent");
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev) && ev.getPointerCount()==1;
}
// Return false if we're scrolling in the Y direction
class XScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.d(TAG, "onScroll");
super.onScroll(e1, e2, distanceX, distanceY);
if(Math.abs(distanceY) < Math.abs(distanceX)) {
return true;
}
return false;
}
}
}
layout file added as well.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent" >
<mobile.base.SCEScrollViewBase
android:fillViewport="true"
android:id="@+id/warehouseScrollWidget"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scrollbarFadeDuration="999999"
android:scrollbarStyle="outsideOverlay" >
<mobile.base.SCEHorizontalScrollViewBase
android:fillViewport="true"
android:id="@+id/warehouseHorizontalScrollWidget"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scrollbarFadeDuration="999999"
android:scrollbarStyle="outsideOverlay" >
<mobile.base.widgets.SCEWidgetWarehouseView
android:id="@+id/WarehouseView"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</mobile.base.SCEHorizontalScrollViewBase>
</mobile.base.SCEScrollViewBase>
</RelativeLayout>
From my logs I get this.
08-27 15:28:32.376: mobile.base.SCEHorizontalScrollViewBase(21571): requestLayout
08-27 15:28:32.376: mobile.base.widgets.SCEWidgetWarehouseView(21571): requestLayout
08-27 15:28:32.386: mobile.base.SCEScrollViewBase(21571): requestLayout
08-27 15:28:32.386: mobile.base.SCEHorizontalScrollViewBase(21571): requestLayout
08-27 15:28:32.386: mobile.base.SCEScrollViewBase(21571): requestLayout
08-27 15:28:32.416: mobile.base.widgets.SCEWidgetWarehouseView(21571): onMeasure set 972.5,1765.0
08-27 15:28:32.416: mobile.base.widgets.SCEWidgetWarehouseView(21571): onMeasure set 972.5,1765.0
08-27 15:28:32.456: mobile.base.widgets.SCEWidgetWarehouseView(21571): onMeasure set 972.5,1765.0
08-27 15:28:32.456: mobile.base.widgets.SCEWidgetWarehouseView(21571): onMeasure set 972.5,1765.0
08-27 15:28:32.476: mobile.base.SCEScrollViewBase(21571): onDraw
08-27 15:28:32.486: mobile.base.SCEHorizontalScrollViewBase(21571): onDraw
08-27 15:28:32.486: mobile.base.widgets.SCEWidgetWarehouseView(21571): onDraw
08-27 15:28:32.877: mobile.base.SCEScrollViewBase(21571): onDraw
08-27 15:28:32.877: mobile.base.SCEHorizontalScrollViewBase(21571): onDraw
08-27 15:28:32.877: mobile.base.widgets.SCEWidgetWarehouseView(21571): onDraw
08-27 15:28:33.117: mobile.base.SCEScrollViewBase(21571): onDraw
08-27 15:28:33.117: mobile.base.SCEHorizontalScrollViewBase(21571): onDraw
08-27 15:28:33.117: mobile.base.widgets.SCEWidgetWarehouseView(21571): onDraw
Any ideas why it is doing this? It did not do this before, something changed and I don't know what. The screen used to scroll fairly faster before, and now it barely moves.