4

Problem

I need to give some priority for scrolling events in my Activity.

I'm using aiCharts (charts library) and I need to zoom, pan, etc. on my areas. Without any ScrollViews it works fine, but, if I use the mentioned Layout, these features works bad. I think because of priority of views.

Possible solution

I tried to use setOverScrollMode(View.OVER_SCROLL_ALWAYS); on views that need to be on "top" of ScrollView and HorizontalScrollView but doesn't work properly.

Layout

 <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <RelativeLayout
                android:id="@+id/screen_relative_layout"
                android:layout_width="wrap_content"
                android:layout_height="match_parent" >
            </RelativeLayout>        
        </HorizontalScrollView>
    </ScrollView>

All my views are added programmatically by adding to RelativeLayout.

Samoji
  • 305
  • 2
  • 3
  • 11

1 Answers1

0

Change your RelativeLayout so that the android:layout_height="wrap_content" Also do your own custom scrollview so that it intercepts the movement and nothing else:

public class VerticalScrollView extends ScrollView {
private float xDistance, yDistance, lastX, lastY;

public VerticalScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            xDistance = yDistance = 0f;
            lastX = ev.getX();
            lastY = ev.getY();
            break;
        case MotionEvent.ACTION_MOVE:
            final float curX = ev.getX();
            final float curY = ev.getY();
            xDistance += Math.abs(curX - lastX);
            yDistance += Math.abs(curY - lastY);
            lastX = curX;
            lastY = curY;
            if(xDistance > yDistance)
                return false;
    }

    return super.onInterceptTouchEvent(ev);
}
}  

source

Let me know how that worked!

Community
  • 1
  • 1
Dyna
  • 2,304
  • 1
  • 14
  • 25
  • It works if the RelativeLayout is not scrollable. If the view dimension is bigger than screen resolution, scroll become active and I have the same issue. – Samoji Sep 03 '13 at 07:55
  • you have to create a custom scrollview so that the only touches you intercept are the ones from x to y here is a sample: http://stackoverflow.com/a/2655740/1182971 And a custom horizontal scrollview that also just intercepts when you go from left to right and right to left. Hope it helps you. – Dyna Sep 03 '13 at 09:21