com.github.ksoichiro.android.observablescrollview.ObservableScrollView Java Examples
The following examples show how to use
com.github.ksoichiro.android.observablescrollview.ObservableScrollView.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserDataActivity.java From Conquer with Apache License 2.0 | 6 votes |
private void bindViews() { scrollView = (ObservableScrollView) findViewById(R.id.sv); title_bg = findViewById(R.id.title_bg); iv_photo = (CircularImageView) findViewById(R.id.iv_photo); material_menu = (MaterialMenuView) findViewById(R.id.material_menu); tv_nickname = (TextView) findViewById(R.id.tv_nickname); iv_gender = (ImageView) findViewById(R.id.iv_gender); iv_home_bg = (ImageView) findViewById(R.id.iv_home_bg); album = findViewById(R.id.album); data = findViewById(R.id.data); tv_id = (TextView) findViewById(R.id.tv_id); et_city = (TextView) findViewById(R.id.et_city); et_phone = (TextView) findViewById(R.id.et_phone); topView = findViewById(R.id.topView); iv_camera = findViewById(R.id.iv_camera); ll_album = (ViewGroup) findViewById(R.id.ll_album); ll_label = (ViewGroup) findViewById(R.id.ll_label); bt_eidt = findViewById(R.id.bt_eidt); add = View.inflate(context, R.layout.item_album, null); add_pic = (ImageView) add.findViewById(R.id.iv_pic); }
Example #2
Source File: StickyHeaderWebViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stickyheaderwebview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); mHeaderView = findViewById(R.id.header); ViewCompat.setElevation(mHeaderView, getResources().getDimension(R.dimen.toolbar_elevation)); mToolbarView = findViewById(R.id.toolbar); mScrollView = (ObservableScrollView) findViewById(R.id.scroll); mScrollView.setScrollViewCallbacks(mScrollViewScrollCallbacks); ObservableWebView mWebView = (ObservableWebView) findViewById(R.id.web); mWebView.setScrollViewCallbacks(mWebViewScrollCallbacks); mWebView.loadUrl("file:///android_asset/lipsum.html"); }
Example #3
Source File: ViewPagerTabScrollViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_scrollview, container, false); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); Activity parentActivity = getActivity(); if (parentActivity instanceof ObservableScrollViewCallbacks) { // Scroll to the specified offset after layout Bundle args = getArguments(); if (args != null && args.containsKey(ARG_SCROLL_Y)) { final int scrollY = args.getInt(ARG_SCROLL_Y, 0); ScrollUtils.addOnGlobalLayoutListener(scrollView, new Runnable() { @Override public void run() { scrollView.scrollTo(0, scrollY); } }); } scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity); } return view; }
Example #4
Source File: ViewPagerTabActivity.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private void propagateToolbarStateForScrollView(boolean isShown, View view, int toolbarHeight) { ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); if (scrollView == null) { return; } if (isShown) { // Scroll up if (0 < scrollView.getCurrentScrollY()) { scrollView.scrollTo(0, 0); } } else { // Scroll down (to hide padding) if (scrollView.getCurrentScrollY() < toolbarHeight) { scrollView.scrollTo(0, toolbarHeight); } } }
Example #5
Source File: HollyViewPagerAnimator.java From HollyViewPager with Apache License 2.0 | 6 votes |
public void registerScrollView(final ObservableScrollView scrollView) { scrolls.add(scrollView); if (scrollView.getParent() != null && scrollView.getParent().getParent() != null && scrollView.getParent().getParent() instanceof ViewGroup) scrollView.setTouchInterceptionViewGroup((ViewGroup) scrollView.getParent().getParent()); scrollView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() { @Override public void onScrollChanged(int i, boolean b, boolean b1) { onScroll(scrollView, i); } @Override public void onDownMotionEvent() { } @Override public void onUpOrCancelMotionEvent(ScrollState scrollState) { } }); }
Example #6
Source File: ViewPagerTabActivity.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private void adjustToolbarForScrollViews(ScrollState scrollState, View view) { int toolbarHeight = mToolbarView.getHeight(); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); if (scrollView == null) { return; } if (scrollState == ScrollState.UP) { if (toolbarHeight < scrollView.getCurrentScrollY()) { hideToolbar(); } else if (scrollView.getCurrentScrollY() < toolbarHeight) { showToolbar(); } } else if (scrollState == ScrollState.DOWN) { if (toolbarHeight < scrollView.getCurrentScrollY()) { showToolbar(); } } }
Example #7
Source File: DetailsActivity.java From Material-Design-Example with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_details); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mImageView = findViewById(R.id.image); mToolbarView = findViewById(R.id.toolbar); mToolbarView.setBackgroundColor(ScrollUtils.getColorWithAlpha(0, getResources().getColor(R.color.theme_dialer_primary))); mScrollView = (ObservableScrollView) findViewById(R.id.scroll); mScrollView.setScrollViewCallbacks(this); mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.drawer_menu_width); }
Example #8
Source File: ParallaxToolbarScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_parallaxtoolbarscrollview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); mImageView = findViewById(R.id.image); mToolbarView = findViewById(R.id.toolbar); mToolbarView.setBackgroundColor(ScrollUtils.getColorWithAlpha(0, getResources().getColor(R.color.primary))); mScrollView = (ObservableScrollView) findViewById(R.id.scroll); mScrollView.setScrollViewCallbacks(this); mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.parallax_image_height); }
Example #9
Source File: HandleTouchScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_handletouchscrollview); ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll); scrollView.setScrollViewCallbacks(this); int[] ids = new int[]{R.id.button1, R.id.button2, R.id.button3}; for (int i = 0; i < ids.length; i++) { final int number = i + 1; findViewById(ids[i]).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { click(number); } }); } }
Example #10
Source File: ToolbarControlWebViewActivity.java From UltimateAndroid with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.observable_scroll_view_activity_toolbarcontrolwebview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); mHeaderView = findViewById(R.id.header); ViewCompat.setElevation(mHeaderView, getResources().getDimension(R.dimen.toolbar_elevation)); mToolbarView = findViewById(R.id.toolbar); mScrollView = (ObservableScrollView) findViewById(R.id.scroll); mScrollView.setScrollViewCallbacks(mScrollViewScrollCallbacks); ObservableWebView mWebView = (ObservableWebView) findViewById(R.id.web); mWebView.setScrollViewCallbacks(mWebViewScrollCallbacks); mWebView.loadUrl("file:///android_asset/lipsum.html"); }
Example #11
Source File: ParallaxToolbarScrollViewActivity.java From UltimateAndroid with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.observable_scroll_view_activity_parallaxtoolbarscrollview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); mImageView = findViewById(R.id.image); mToolbarView = findViewById(R.id.toolbar); setBackgroundAlpha(mToolbarView, 0, getResources().getColor(R.color.primary)); ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll); scrollView.setScrollViewCallbacks(this); mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.parallax_image_height); }
Example #12
Source File: ViewPagerTabScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
private void propagateToolbarState(boolean isShown) { int toolbarHeight = mToolbarView.getHeight(); // Set scrollY for the fragments that are not created yet mPagerAdapter.setScrollY(isShown ? 0 : toolbarHeight); // Set scrollY for the active fragments for (int i = 0; i < mPagerAdapter.getCount(); i++) { // Skip current item if (i == mPager.getCurrentItem()) { continue; } // Skip destroyed or not created item Fragment f = mPagerAdapter.getItemAt(i); if (f == null) { continue; } View view = f.getView(); if (view == null) { continue; } ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); if (isShown) { // Scroll up if (0 < scrollView.getCurrentScrollY()) { scrollView.scrollTo(0, 0); } } else { // Scroll down (to hide padding) if (scrollView.getCurrentScrollY() < toolbarHeight) { scrollView.scrollTo(0, toolbarHeight); } } } }
Example #13
Source File: FlexibleSpaceWithImageScrollViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void updateFlexibleSpace(int scrollY, View view) { ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); // Also pass this event to parent Activity FlexibleSpaceWithImageWithViewPagerTabActivity parentActivity = (FlexibleSpaceWithImageWithViewPagerTabActivity) getActivity(); if (parentActivity != null) { parentActivity.onScrollChanged(scrollY, scrollView); } }
Example #14
Source File: ViewPagerTabScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onUpOrCancelMotionEvent(ScrollState scrollState) { mBaseTranslationY = 0; Fragment fragment = getCurrentFragment(); if (fragment == null) { return; } View view = fragment.getView(); if (view == null) { return; } int toolbarHeight = mToolbarView.getHeight(); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); if (scrollView == null) { return; } int scrollY = scrollView.getCurrentScrollY(); if (scrollState == ScrollState.DOWN) { showToolbar(); } else if (scrollState == ScrollState.UP) { if (toolbarHeight <= scrollY) { hideToolbar(); } else { showToolbar(); } } else { // Even if onScrollChanged occurs without scrollY changing, toolbar should be adjusted if (toolbarIsShown() || toolbarIsHidden()) { // Toolbar is completely moved, so just keep its state // and propagate it to other pages propagateToolbarState(toolbarIsShown()); } else { // Toolbar is moving but doesn't know which to move: // you can change this to hideToolbar() showToolbar(); } } }
Example #15
Source File: ViewPagerTabScrollViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_scrollview, container, false); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); Activity parentActivity = getActivity(); if (parentActivity instanceof ObservableScrollViewCallbacks) { // Scroll to the specified offset after layout Bundle args = getArguments(); if (args != null && args.containsKey(ARG_SCROLL_Y)) { final int scrollY = args.getInt(ARG_SCROLL_Y, 0); ScrollUtils.addOnGlobalLayoutListener(scrollView, new Runnable() { @Override public void run() { scrollView.scrollTo(0, scrollY); } }); } // TouchInterceptionViewGroup should be a parent view other than ViewPager. // This is a workaround for the issue #117: // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117 scrollView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root)); scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity); } return view; }
Example #16
Source File: StickyHeaderScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stickyheaderscrollview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); mHeaderView = findViewById(R.id.header); ViewCompat.setElevation(mHeaderView, getResources().getDimension(R.dimen.toolbar_elevation)); mToolbarView = findViewById(R.id.toolbar); mScrollView = (ObservableScrollView) findViewById(R.id.scroll); mScrollView.setScrollViewCallbacks(this); }
Example #17
Source File: ViewPagerTab2ScrollViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_scrollview_noheader, container, false); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); Activity parentActivity = getActivity(); scrollView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container)); if (parentActivity instanceof ObservableScrollViewCallbacks) { scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity); } return view; }
Example #18
Source File: ViewPagerTabFragmentScrollViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_scrollview_noheader, container, false); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); Fragment parentFragment = getParentFragment(); ViewGroup viewGroup = (ViewGroup) parentFragment.getView(); if (viewGroup != null) { scrollView.setTouchInterceptionViewGroup((ViewGroup) viewGroup.findViewById(R.id.container)); if (parentFragment instanceof ObservableScrollViewCallbacks) { scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentFragment); } } return view; }
Example #19
Source File: FlexibleSpaceToolbarScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_flexiblespacetoolbarscrollview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); ActionBar ab = getSupportActionBar(); if (ab != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } mFlexibleSpaceView = findViewById(R.id.flexible_space); mTitleView = (TextView) findViewById(R.id.title); mTitleView.setText(getTitle()); setTitle(null); mToolbarView = findViewById(R.id.toolbar); final ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll); scrollView.setScrollViewCallbacks(this); mFlexibleSpaceHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_height); int flexibleSpaceAndToolbarHeight = mFlexibleSpaceHeight + getActionBarSize(); findViewById(R.id.body).setPadding(0, flexibleSpaceAndToolbarHeight, 0, 0); mFlexibleSpaceView.getLayoutParams().height = flexibleSpaceAndToolbarHeight; ScrollUtils.addOnGlobalLayoutListener(mTitleView, new Runnable() { @Override public void run() { updateFlexibleSpaceText(scrollView.getCurrentScrollY()); } }); }
Example #20
Source File: FlexibleSpaceWithImageScrollViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_flexiblespacewithimagescrollview, container, false); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); // TouchInterceptionViewGroup should be a parent view other than ViewPager. // This is a workaround for the issue #117: // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117 scrollView.setTouchInterceptionViewGroup((ViewGroup) view.findViewById(R.id.fragment_root)); // Scroll to the specified offset after layout Bundle args = getArguments(); if (args != null && args.containsKey(ARG_SCROLL_Y)) { final int scrollY = args.getInt(ARG_SCROLL_Y, 0); ScrollUtils.addOnGlobalLayoutListener(scrollView, new Runnable() { @Override public void run() { scrollView.scrollTo(0, scrollY); } }); updateFlexibleSpace(scrollY, view); } else { updateFlexibleSpace(0, view); } scrollView.setScrollViewCallbacks(this); return view; }
Example #21
Source File: UserInfoFragment.java From MaterialWeCenter with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mScrollView = (ObservableScrollView) view.findViewById(R.id.scrollView); fans = (TextView) view.findViewById(R.id.fans); agree = (TextView) view.findViewById(R.id.agree); thanks = (TextView) view.findViewById(R.id.thanks); signature = (TextView) view.findViewById(R.id.signature); city = (TextView) view.findViewById(R.id.city); MaterialViewPagerHelper.registerScrollView(getActivity(), mScrollView, null); new LoadUserInfo().execute(); }
Example #22
Source File: ViewPagerTab2ScrollViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_scrollview_noheader, container, false); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); Activity parentActivity = getActivity(); scrollView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container)); if (parentActivity instanceof ObservableScrollViewCallbacks) { scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity); } return view; }
Example #23
Source File: TouchInterceptionScrollViewActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(true); activity = getActivity(); scrollable = (ObservableScrollView) activity.findViewById(R.id.scrollable); }
Example #24
Source File: ScrollViewActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(true); activity = getActivity(); scrollable = (ObservableScrollView) activity.findViewById(R.id.scrollable); callbackCounter = new int[2]; }
Example #25
Source File: ScrollViewActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
public void testInitialize() throws Throwable { runTestOnUiThread(new Runnable() { @Override public void run() { new ObservableScrollView(activity); new ObservableScrollView(activity, null, 0); } }); }
Example #26
Source File: ScrollViewActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
public void testNoCallbacks() throws Throwable { runTestOnUiThread(new Runnable() { @Override public void run() { scrollable = (ObservableScrollView) activity.findViewById(R.id.scrollable); scrollable.setScrollViewCallbacks(null); } }); testScroll(); }
Example #27
Source File: ParallaxViewController.java From Carpaccio with Apache License 2.0 | 5 votes |
public void registerParallax(ScrollView view, boolean replaceWithObservableScrollView) { if (replaceWithObservableScrollView && !(view instanceof ObservableScrollView)) { CommonViewController replaceViewController = new CommonViewController(); ObservableScrollView newView = replaceViewController.replaceViewithTagToRemove(view, "com.github.ksoichiro.android.observablescrollview.ObservableScrollView", "registerParallax()"); if (view.getChildCount() > 0) { View scrollViewChild = view.getChildAt(0); view.removeView(scrollViewChild); newView.addView(scrollViewChild); } view = newView; } if (view != null) ((ObservableScrollView) view).setScrollViewCallbacks(new ObservableScrollViewCallbacks() { @Override public void onScrollChanged(int i, boolean b, boolean b1) { scrolled(i); } @Override public void onDownMotionEvent() { } @Override public void onUpOrCancelMotionEvent(ScrollState scrollState) { } }); }
Example #28
Source File: ActionBarControlScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_actionbarcontrolscrollview); ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll); scrollView.setScrollViewCallbacks(this); }
Example #29
Source File: FlexibleSpaceToolbarScrollViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.observable_scroll_view_activity_flexiblespacetoolbarscrollview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mFlexibleSpaceView = findViewById(R.id.flexible_space); mTitleView = (TextView) findViewById(R.id.title); mTitleView.setText(getTitle()); setTitle(null); mToolbarView = findViewById(R.id.toolbar); final ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll); scrollView.setScrollViewCallbacks(this); mFlexibleSpaceHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_height); int flexibleSpaceAndToolbarHeight = mFlexibleSpaceHeight + getActionBarSize(); findViewById(R.id.body).setPadding(0, flexibleSpaceAndToolbarHeight, 0, 0); mFlexibleSpaceView.getLayoutParams().height = flexibleSpaceAndToolbarHeight; ViewTreeObserver vto = mTitleView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { mTitleView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { mTitleView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } updateFlexibleSpaceText(scrollView.getCurrentScrollY()); } }); }
Example #30
Source File: ViewPagerTabScrollViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
private void propagateToolbarState(boolean isShown) { int toolbarHeight = mToolbarView.getHeight(); // Set scrollY for the fragments that are not created yet mPagerAdapter.setScrollY(isShown ? 0 : toolbarHeight); // Set scrollY for the active fragments for (int i = 0; i < mPagerAdapter.getCount(); i++) { // Skip current item if (i == mPager.getCurrentItem()) { continue; } // Skip destroyed or not created item Fragment f = mPagerAdapter.getItemAt(i); if (f == null) { continue; } ObservableScrollView scrollView = (ObservableScrollView) f.getView().findViewById(R.id.scroll); if (isShown) { // Scroll up if (0 < scrollView.getCurrentScrollY()) { scrollView.scrollTo(0, 0); } } else { // Scroll down (to hide padding) if (scrollView.getCurrentScrollY() < toolbarHeight) { scrollView.scrollTo(0, toolbarHeight); } } } }