how to use parallel scrolling in android with two views - android

I am trying to use parallel scrolling in android.i.e.i have two view in a layout a mapview on the top and a listview in the bottom.when i scroll up in the listview, the mapview should also scrollup.as we keep scrolling the list should cover the whole screen.
i have tried getting the cordinates of the listview using the ViewTreeObserver.onGlobalLayoutListenerand
moving the listview on touch,which is not working out. can i get any suggestions on how to proceed.
Edit: I managed to get desired effect using parallaxScrollview. But how do i make the backGround image clickable in parallaxscrollview

You'll have to register for the onTouch of the listView and dynamically change the position and the size of the two components with every variation on the Y axis

Related

A recycler view vs the linear layout inside a scroll view?

Am trying to create a page with a scrollable list. Features would be a normal list to remove item by clicking on it. Number of items in that list are limited and added dynamically by user. You can consider a to do list as example. Now which would be a better approach to implement it? Recycler view with data bound to its adapter? Or the normal linear layout with items added as children at run time?
My current implementation is recycler view. But,I found it lagging and animations are not performing well. So a linear layout is auto animated by specifying it xml -- by setting animate layout changes to true.
FYI data is local and syncs in background.
Never use a LinearLayout for anything longer than a single screen. The whole point of ListView and RecyclerView is to efficiently reuse views instead of needing to hold things in memory when they're not visible. Maybe you can refine or reask your question so people can help you with whatever difficulty you're having with animations, rather than avoiding the issue.

How put Horizontal View and Gridview inside Vertical Scrollview

I want to develop an app that includes GridView and I want it to be some thing like horizontal ListView above a gridvew .Horizontal view displays images downloaded from url.I saw this touturial ( horizontal scrollview used)
and saw this to put the GridView inside scrollView because i want to put the gridview(episode #2) and horizontal view (episode #1) in vertical scrollview(episode #3) . I need to scroll the horizontal view vertically when a user is scrolling the gridview and not to have fixed position at the top of the screen.
I have no idea how to do this (use horizontal ScrollView or horizontal Listview)?
after vertical scrolling I want it to be like this (horizontal view must get scrolled vertically):
This is a custom interaction, so you probably will not be able to use a "standard" tool for this. You may want something like the FloatingActionButton (an example here: http://antonioleiva.com/collapsing-toolbar-layout/) but you also want it to scroll, so you may need to extend that class.
Also, you could use touch events to do a custom animation on the area, because you will need to track when it is displayed and the direction/distance of the motion event to collapse/expand it. You also would need to know anchors on the list, to determine when it should reappear...
This is a cool design concept, but usually "cool" = "difficult" because it's not standard.

Android ViewPager set current element always on center

I need a vertical ViewPager that has selected view always on center.
Something like Android's gallery widget works (selected element is always in center).
I have tried to implement vertical Gallery, but since it's deprecated...I would like to have this functionality via ViewPager.
Is there a way to manage that selected view is always on the center?
Also how to manage scroll amount of ViewPager?
For example...when I scroll trough the content I want to scroll for exactly one element's height.
Also I need mechanism how to define exact amouth of pixels for scrolling list view.
When list scroll I don't want it to only show next item, but to scroll for exact amount of pixels to always show the part of the following item.
Tnx for your help!
Im not sure if i understund the question. Isn't it as easy as this?
viewPager.setCurrentItem(viewager.getAdapter().getCount()/2)
About scrolling the pager to an specific amount of pixels,
You have to signal the ViewPager by calling beginFakeDrag() and endFakeDrag() on it. After starting a fake drag you can use fakeDragBy(float) to drag the ViewPager by the given amount of pixels

DirectionalViewPager with 30 buttons in every page

I am trying to use DirectionalViewPager for displaying 30 buttons in every page. Normally this viewpager is working perfectly. But, if I try this pager after adding buttons then the touch is not sensible or smoother. I observe lag and irregular touch sense when there are some clickable items on the fragment.
When I try dragging the pages by dragging using non-clickable items, then its working perfectly.
Can any one assist me to handle this issue?
This issue occurred due to the Child buttons in the gridview. Because If we override onTouch method for the Button then the X and Y points are given with respect to that particular button only. So if you are passing these values to the parent then you should change the values according to the parent or else you can directly pass the Button's X,Y points which will improve the Touch sensitivity more.

Android - How to determinate ViewFlipper children size when not displayed?

I'm actually making an application using a ViewFlipper to display 3 differents custom views. These views are, for each one, in a ScrollView (putting the ViewFlipper in a single ScrollView isn't making my onFling gestures really efficient). And i'm actually trying to synchronize the three Scrollbars position. At this point using a single ScrollView would have been easier but i trying to not use this solution.
I'm using a ScrollListener for each ScrollView to set the others ScrollView scroll position like in this thread : Synchronise ScrollView scroll positions - android.
The problem is that this method will works but the first time. When i'm on a ScrollView, the two others are not drawn already and their height is null. So setting their scroll position isn't working.
/*Instanciate ScollViews*/
scrollViewLeft = (ScrollableScrollView) findViewById(R.id.scroll_prev);
scrollViewCenter =(ScrollableScrollView) findViewById(R.id.scroll_current);
scrollViewRight = (ScrollableScrollView) findViewById(R.id.scroll_next);
/*Fill views with events*/
setDayEvents(calIns.getPrevCal(),leftDayView);
setDayEvents(calIns.getActualCal(),centerDayView);
setDayEvents(calIns.getNextCal(),rightDayView);
scrollViewLeft.setScrollViewListener(this);
scrollViewCenter.setScrollViewListener(this);
scrollViewRight.setScrollViewListener(this);
So finally my question is, should i use another method to find the scroll position of the two others views ? Or can i force the view to be drawn in a ViewFlipper ?
Thanks :)
Clement.
Try saving the positions in global variables before you change the views and then just apply it to your current view.
Thanks Egor for having answered. I think it is a good idea. I already have a Singleton to handle variables. So i add the variable position with getters and setters.
The probleme here is than even if I override the method "onSizeChanged" in my custom ScrollView, this will apply only for the first view shown.
PS: I'm still starting on Android development and I don't really know how to handle with
interactions on views when they aren't ready (for example getting width when they are not drawn yet).
Edit 1 day later :
Ok i found what was the problem, it is because the size of my views inside the scrollviews wasn't defined (the scrollview was drawn before the view inside it). So by setting the scroll inside the "onSizeChanged" method of the views works well.

Categories

Resources