Android:RealViewSwitcher 不垂直滚动 [英] Android: RealViewSwitcher don't scrolling in vertical

查看:48
本文介绍了Android:RealViewSwitcher 不垂直滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 RealViewSwitcher 来滑动视图,没关系,我的问题类似于这个 一.我将尝试通过这张图片来解释一下我的场景

im using RealViewSwitcher to swipe view and it's ok, my problem is similar to this one. i will try to explain a bit my scenario by this pic

listview <------> 详细视图------> 滑动视图(水平).详细视图仅显示部分内容,如果尝试滚动则不会发生任何事情.

listview <------> detail view ------> swipe view (horizontal). The detail view is showing only partially and if try to scroll nothing happens.

细节布局(无垂直滚动)

Detail layout (no vertical scrolling)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

     <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColorHint="#FF0000"
        android:textSize="12dp"
        android:textStyle="bold"
        android:typeface="sans" />

         <ImageView
            android:id="@+id/imageView1"
            android:layout_width="150dip"
            android:layout_height="120dip"
            android:scaleType="centerCrop"
            android:src="@drawable/stub"/>   
   <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="20dip"
        android:textColor="#999999"
        android:textColorLink="#ff0000"
        android:textSize="20dip"
        android:textStyle="normal"
        android:typeface="sans" />
</LinearLayout>

使用 RealViewSwitcher 进行布局

layout with RealViewSwitcher

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical">

    <it.application.ppn.lib.RealViewSwitcher
        android:id="@+id/horizontal_pager"
        android:layout_width="fill_parent"
        android:layout_height="0px"
        android:layout_weight="1">

    </it.application.ppn.lib.RealViewSwitcher>

</LinearLayout>

推荐答案

我遇到了同样的问题,通过在 RealViewSwitcher 中拦截触摸事件找到了解决方案.

I faced with the same problem and found solution by intercepting touch event in RealViewSwitcher.

之前发布的变体不适用于较新的 API.代码有第三次修订.

previous posted variant does not work on newer API. There is third revision of code.

将这些行添加到 RealViewSwitcher 实现中:

Add those lines into RealViewSwitcher implementation:

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {

    // prevent vertical scrolling when view switching in progress 
    if (!mScroller.isFinished())
        return true;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mScrollLocked = false;
        mLastX = event.getX();
        mLastY = event.getY();
        mDeltaX = 0;
        mDeltaY = 0;
        onTouchEvent(event);
        break;

    case MotionEvent.ACTION_MOVE:
        final float x = event.getX();
        final float y = event.getY();
        mDeltaX += Math.abs(x - mLastX);
        mDeltaY += Math.abs(y - mLastY);
        mLastX = x;
        mLastY = y;
        if (mDeltaX > mDeltaY) {
            mScrollLocked = true;
            onTouchEvent(event);
        } else {
            snapToDestination();
        }
        break;
    }

    if (mScrollLocked)
        return true; // prevent furhter processing

    return super.onInterceptTouchEvent(event);
}

还需要编辑onTouchEvent方法并替换case MotionEvent.ACTION_DOWN: body如下:

also need to edit onTouchEvent method and replace case MotionEvent.ACTION_DOWN: body as follows:

    case MotionEvent.ACTION_DOWN:

        /*
         * If being flinged and user touches, stop the fling. isFinished will be false if being flinged.
         */
        mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;

        if (mTouchState == TOUCH_STATE_SCROLLING) {
            mScroller.abortAnimation();
        }

        // Remember where the motion event started
        mLastMotionX = x;

        break;

这篇关于Android:RealViewSwitcher 不垂直滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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