ViewPager how to draw view only if caption is PagerTitleStrip
Background:
I have been dealing with this for a long time now and cannot find any decent documentation. I am locked out to support api level 8 and so viewing the pager seemed like a good solution. I worked with pagerTitleStrip. However, I want the user to be able to scroll between views while scrolling on the pagerTitleStrip. It works for me.
Question:
When I scroll to the top (touch_move) of a button, edittext fields, etc. The Viewpager only brings a small snippet of another view to the window. I want nothing to happen if the touchmove event doesn't scroll between the view, it's ontop pagerTitleStrip.
Unable to try:
I have set the onTouchListener from the viewPager and any onTouch event actions (touchmove, touchup, touchdown) that I use to determine if the user is scrolling onto the pagerTitleStrip.
//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;
}
}
source to share