I have a ScrollView with LinearLayout inside it, LinearLayout has several children. One of these children is HorizontalScrollView, which contains navigation options. When the application loads, there is some content at the top, a menu in the middle of the screen and more content below. I would like the menu to scroll up the screen along with the rest of the content, but when it starts to scroll from the screen, block the top view that looks like a title. If the user scrolls back, he should remain pinned until all the content below him scrolls and then starts scrolling again, so if they scroll through the whole screen, itβs like the way it started. I now have this initial attempt, which seems to do nothing:
final View carouselMenu = rootView.findViewById(R.id.carousel_menu); ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.main_scroll); RelativeLayout mainContainer = (RelativeLayout) rootView.findViewById(R.id.main_root_container); scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { if (carouselMenu.getScrollY() < 0) { carouselMenu.setScrollY(0); } } });
setScrollY doesn't seem to set where the βViewβ looks like I hoped. Is there a way to manually override where a particular view is placed on the screen, or a better method that I have not considered?
source share