1

我在 scoll 视图中使用图库视图,但图库视图无法正常工作。

我的自定义 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 回答