首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ViewPager如何在PagerTitleStrip之上仅滑动视图

ViewPager如何在PagerTitleStrip之上仅滑动视图
EN

Stack Overflow用户
提问于 2013-01-24 03:43:16
回答 1查看 645关注 0票数 3

背景故事:

我已经在这个问题上折腾了一段时间了,找不到任何像样的文档。我不得不支持api level 8,因此view pager似乎是一个很好的解决方案。我已经让它和pagerTitleStrip一起工作了。但是,我只希望用户在pagerTitleStrip上滑动时能够在视图之间滑动。我在一定程度上做到了这一点。

问题:

当我在按钮、编辑文本字段等的顶部(touch_move)滑动时,视图分页只将其他视图的一小部分带到窗口中。我不希望发生任何事情,除非在视图之间滑动的touchmove事件位于pagerTitleStrip的顶部。

尝试失败:

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

代码语言:javascript
复制
//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;
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2013-01-29 04:44:17

使用带有按钮的ViewFlipper来切换内容,或者使用动作栏标签,或者类似的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14488022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档