3

背景故事:

我已经搞砸了一段时间,找不到任何像样的文档。我被锁定必须支持 api 级别 8,因此查看寻呼机似乎是一个很好的解决方案。我已经让它与 pagerTitleStrip 一起工作。但是,我只希望用户在 pagerTitleStrip 上滑动时能够在视图之间滑动。我有一些工作。

问题:

当我在按钮、edittext 字段等的顶部 (touch_move) 上滑动时。viewpager 仅将一小部分其他视图带入窗口。除非在视图之间滑动的 touchmove 事件位于 pagerTitleStrip 之上,否则我不希望发生任何事情。

失败的尝试:

我已经设置了 viewPager 的 onTouchListener 和我用来确定用户是否在 pagerTitleStrip 上滑动的任何 onTouch 事件操作(touchmove、touchup、touchdown)。

//in onCreate()
...
setContentView(R.layout.pager_adapter);
dashboardPagerAdapter = new DashboardPagerAdapter(
getSupportFragmentManager());
dashboardViewPager = (ViewPager) findViewById(R.id.dashboard_pager);
dashboardViewPager.setAdapter(dashboardPagerAdapter);
dashboardViewPager.setId(R.layout.activity_dashboard);
dashboardViewPager.setCurrentItem(DashboardPagerAdapter.DASHBOARD);
dashboardViewPager.setOnTouchListener(this);
...

// in onTouch
View pagerTitleArea = findViewById(R.id.pager_title_strip);
    int pagerTitleBottomYLocation = pagerTitleArea.getBottom();
    initialYPositionOfEvent = 100; // set the initial position out of range.
    int action = event.getAction();

    if (action == MotionEvent.ACTION_DOWN){
        initialYPositionOfEvent = event.getY();
        originWasTitleBar = (initialYPositionOfEvent > pagerTitleBottomYLocation) ? false : true ;
        hasTouchDownEventOccured = true;
        return true;
    } else if (action == MotionEvent.ACTION_MOVE){
        if(originWasTitleBar && hasTouchDownEventOccured){
            return false;
        } else {
            return true;
        }
    } else {
        if(originWasTitleBar && hasTouchDownEventOccured){
            originWasTitleBar = false;
            hasTouchDownEventOccured = false;
            return false;
        } else {
            originWasTitleBar = false;
            hasTouchDownEventOccured = false;
            return true;
        }
    }
4

1 回答 1

0

使用带有按钮的 ViewFlipper 来切换内容,或者使用操作栏选项卡,或者类似的东西,也许。

于 2013-01-28T20:44:16.900 回答