滚动视图里面图库视图不工作。 [英] Gallery View inside scroll view not working.

查看:144
本文介绍了滚动视图里面图库视图不工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的图库查看scoll看法,但无法正常工作画廊视图中。

I'm using gallery view inside scoll view but gallery view not working properly.

我的自定义图库视图

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

我的问题是滚动型(垂直)工作的罚款。该图库视图(水平)刷卡不工作...

My problem is scrollview(vertically) working fine. The galleryview(horizontally) swiping is not working...

推荐答案

这是众所周知的bug:滚动型拦截水平和垂直触摸事件。您可以使用此自定义滚动视图,而不是标准之一。这仅拦截垂直触摸:

This is well known bug: ScrollView intercept both horizontal and vertical touch events. You can use this custom scroll view instead of standard one. This intercept only vertical touches:

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

}

这篇关于滚动视图里面图库视图不工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆