4

問題

アクティビティのスクロール イベントに優先順位を付ける必要があります。

aiCharts (チャート ライブラリ) を使用しており、自分の領域でズーム、パンなどを行う必要があります。何もしなくてもScrollViews問題なく動作しますが、前述の を使用するとLayout、これらの機能がうまく機能しません。ビューの優先順位のためだと思います。

考えられる解決策

andsetOverScrollMode(View.OVER_SCROLL_ALWAYS);の「上」にある必要があるビューで使用しようとしましたが、正しく機能しません。ScrollViewHorizontalScrollView

レイアウト

 <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>

私のすべてのビューは、RelativeLayout に追加することによってプログラムで追加されます。

4

1 に答える 1

0

RelativeLayout を変更android:layout_height="wrap_content" して、独自のカスタム スクロールビューも実行し、動きだけを傍受するようにします。

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);
}
}  

ソース

それがどのように機能したか教えてください!

于 2013-09-02T14:00:07.763 に答える