背景故事:
我已经在这个问题上折腾了一段时间了,找不到任何像样的文档。我不得不支持api level 8,因此view pager似乎是一个很好的解决方案。我已经让它和pagerTitleStrip一起工作了。但是,我只希望用户在pagerTitleStrip上滑动时能够在视图之间滑动。我在一定程度上做到了这一点。
问题:
当我在按钮、编辑文本字段等的顶部(touch_move)滑动时,视图分页只将其他视图的一小部分带到窗口中。我不希望发生任何事情,除非在视图之间滑动的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;
}
}发布于 2013-01-29 04:44:17
使用带有按钮的ViewFlipper来切换内容,或者使用动作栏标签,或者类似的东西。
https://stackoverflow.com/questions/14488022
复制相似问题