1

スクロール ビュー内でギャラリー ビューを使用していますが、ギャラリー ビューが正しく機能しません。

私のカスタム GalleryView

<com.divum.Adapter.CustomGallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:spacing="10dp" />

アダプターのレイアウト

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/top_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="2dp"
android:orientation="vertical"
android:weightSum="100">
<TextView 
android:id="@+id/txt_title1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:padding="5dp"
android:textColor="@color/black"
android:textSize="14dp" />      
<ImageView 
android:id="@+id/image1"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:layout_marginTop="2dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop" 
android:layout_marginLeft="2dp" />
<ScrollView 
android:scrollHorizontally="false"
android:fadingEdge="none"
android:scrollbars="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView 
android:id="@+id/txt_details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:padding="5dp"
android:textColor="@color/black"
android:textSize="14dp" />      
</ScrollView>
</LinearLayout>

私の問題は、スクロールビュー(垂直方向)が正常に機能していることです。ギャラリー ビュー (水平方向) のスワイプが機能しません...

4

1 に答える 1

1

これはよく知られたバグです:ScrollView水平および垂直の両方のタッチ イベントをインターセプトします。標準のスクロール ビューの代わりに、このカスタム スクロール ビューを使用できます。このインターセプトは垂直方向のタッチのみです:

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-01-09T10:41:26.977 に答える