-
-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use this for fragments containing layouts other than ListViews? #5
Comments
Its not working for ScrollViews at all. |
Hi agnel, I'd also be very interested in using this with ScrollViews! Have you find any solution to this problem? |
So, I found a solution : it's working, but it's probably not the best solution in terms of performance and it may be buggy (didn't notice any bug yet though). Just in case somebody would look for this answer, here are the steps to use ScrollViews in the ViewPager :
@Override
public void adjustScroll(int scrollHeight, int headerTranslationY)
{
scrollView.setScrollY(headerTranslationY - scrollHeight);
}
@Override
public void onScrollChanged(ScrollView view, int l, int t, int oldl, int oldt)
{
if (mScrollTabHolder != null)
mScrollTabHolder.onScroll(view, l, t, oldl, oldt, pagePosition);
}
@Override
public void onScroll(ScrollView view, int x, int y, int oldX, int oldY, int pagePosition)
{
if (viewPager.getCurrentItem() == pagePosition)
{
foodtruckHeader.setTranslationY(Math.max(-view.getScrollY(), minHeaderTranslation));
float ratio = clamp(foodtruckHeader.getTranslationY() / minHeaderTranslation, 0.0f, 1.0f);
setTitleAlpha(clamp(5.0F * ratio - 4.0F, 0.0F, 1.0F));
}
} And this is it! Again, I'm sure this is not the best solution, but... it's working for me. If anyone has a better solution, you're welcome to change this! (*) : I've done this because the methods to set the scroll position are different in ListViews and ScrollViews. In the |
Never been able to find such a post, despite the long hours spent searching... Thanks @yshrsmz ! |
Did anyone succeed doing that example that @yshrsmz gave? @Vieuma |
@androidrio sorry, didn't try it since I found a way by myself! Have you tried the solution I posted above? |
@Vieuma Not yet but I will try it today for sure 👍 |
Thanks @Vieuma. I was out of town for training purpose. I'll definitely try your solution for sure and let you know. |
@Vieuma I tried your solution and it works without any bugs. I have an issue with the adjustScroll method. What are you passing to it? I tried a few things but it doesn't seem correct. |
@eirini91 The only time adjustScroll is called is in the ViewPager.OnPageChangeListener.onPageSelected(int page) method (you can find it in the MainActivity.java on this repo). Here's how I changed it : currentHolder.adjustScroll((int) (headerView.getHeight() + headerView.getTranslationY()), headerView.getHeight()); |
@Vieuma Thanks a lot!! everything works fine now! I was sending the height and the translation as the parameters and I had random "jumps" at the top of the scrollview! Thanks for the fast respond :) |
@Vieuma Can u explain me , what's |
@Adnan9011 I was working on a foodtrucks finder app, I just forgot to replace the var name : foodtruckHeader is actually just the header ViewGroup. The call to setTranslationY(...) allows to move the collapse/expand the header while the user is scrolling. |
The ViewPager in my app contains layouts with ListViews, ExpandableListViews, ScrollView, RelativeLayout and LinearLayout(with a MapFragment in this).
Everything works fine for Tabs containing ListViews and ExpandableListViews! But.. not for the other layouts? How to proceed now?
Please Help me I'm trying to build an app for our college Festival.
Thanks!
The text was updated successfully, but these errors were encountered: