I have implemented this https://stackoverflow.com/a/22797619/3064486 (Vertical ViewPager) in my activity.
The fragments that my adapter puts inside the viewpager is having a scrollview in it.
When I reach the bottom of the scrollview it does not switch page in the viewpager. However, if I swipe from the right or left bottom corner it kind of works, it's a bit hard to explain but it jumps 20-30% of the full swipe (from page 1 to page 2) and if I immediately release it goes back and I can also swipe to continue the page switch.
I believe my scrollview is the problem here..
ViewPager
<com.mypackage.MyVerticalViewPager>
The fragment
<LinearLayout>
<ScrollView>
<!-- massive amount of stuff -->
</ScrollView>
</LinearLayout>
I have tried answers here:
https://stackoverflow.com/a/14435116/3064486
Edit: I tried this
https://github.com/castorflex/VerticalViewPager/blob/master/library/src/main/java/fr/castorflex/android/verticalviewpager/VerticalViewPager.java
And got the vertical scroll to work. The ScrollView also works but when I get to the bottom I need to really FLING the finger to get to the other page. I guess I have to remove some kind of overscroll for the scrollView. Anyone have any idea?
use ListView instead of ScrollView can solve this problem. since ScrollView call parent.requestDisallowInterceptTouchEvent(true) method on its onTouchEvent method, its hard to handle scroll conflicts, I am also working with this problem, I will give my solution when done.
Related
I'm trying to use a vertical scrollview in conjunction with a vertical viewpager (see https://github.com/kaelaela/VerticalViewPager), and I'm not sure how to tackle it.
Essentially, I have two fragments, one lower fragment (the one that is defaulted to when the activity starts) which contains a full-screen scrollview, and one upper fragment which I want to reach when the user is at the top of the lower fragment's scrollview and continues to pull down. If anyone has used Facebook messenger, it's similar to their functionality where if you continue to scroll down on their chats page, the camera is started.
Right now, the scrollview blocks the action of opening the second fragment unless i pull down from a very specific angle.
I've considered implementing something using the OnOverScroll method of the scrollview (if Y scroll position is 0), but I feel that would lead to a bad UX because even the slightest overscroll would pull down a whole new fragment.
If anyone has any ideas, I'd be really grateful.
Thanks a lot.
I solved my issue by wrapping my scrollview in a SwipeRefreshLayout. Here are the steps, to help anyone that runs into this issue in the future:
After wrapping your scrollview in the SwipeRefreshLayout, set the layout to transparent in code using mySwipeRefreshLayout.setColorSchemeColors.
Then use
mySwipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
// do your pull-down task here
}
});
to listen for when the user pulls down their scrollview from the top.
Slightly hacky solution but avoids writing custom class extensions that could introduce bugs and uses an existing feature to pretty nicely achieve the desired outcome.
I have a scrollView in my ViewPager fragment. I want to set the initial scrollView position to (0,100).
I tried setting scrollView.scrollTo(0,100) in onCreateView(). It didn't work.
Then I tried the same in Handler and it worked but it only scrolls to (0,100) after (0,0) causing little jerk in scrollView which is bad for user experience.
Is there any way to to make scrollview directly scroll to (0,100) instead of (0,0)? or Is there any method available in scrollView to detect initial scroll event?
P.S :I saw the question here which also the same as mine but the accepted answer is not working for me.
Any help would be appreciated.
Thanks
Instead of scrollTo you can use requestFocus on first child of inner layout of scroll view.
Example:
<ScrollView>
<LinearLayout>
<TextView
android:focusable="true"
android:focusableInTouchMode="true"
android:tag="ScrollTopTag" />
//***rest of your layout***//
</LinearLayout>
</ScrollView>
In your activity where you want to scroll to top of scroll view add below line
View view = findViewByTag("ScrollTopTag);
view.requestFocus();
It feels like you are inflating views inside the adapter without recycling them. This would explain the choppy loading times. Other than that, from the example, try delaying it even more. In the example it uses 250ms, but if your listview it not done loading than its not going to scroll anywhere since it is not filled yet. I would start off but first increasing the duration to about 2000ms just to see if it works. If that works, I would go back to your adapter class and make sure each view is recycling instead of reinflated.
I just discovered Rando app for Android today and I totally felt for the simple UI. I particularly like this sticky red button on their ViewPager:
I know how to make a sticky view over a ViewPager, placing it outside of the ViewPager in the same ViewGroup. But here the red button is partially sticky. When you scroll left, it's scrolling. When you go right, it keeps its position.
Apart from going the ugly way (having two ViewPagers (?!)), I have no idea how they made that. Custom view pager? maybe! Any idea?
I guess one idea would be to detect the page scrolling using onPageScrolled method, detect if scrolling direction is left or right, then manually update the position of the red circle accordingly.
See also:
How to know viewpager is scroll left or right?
Im having trouble with my UI.
It contains a ListView , with ViewPagers as List Items.
The problem is that the horizontal scrolls seem to get interrupted by the ListView (catching vertical scrolls).
What i want to achieve is that no matter what happens, the horizontal scrolls finish all the time. Right now they stop half way sometime.
this is probably a common problem, but i havent found a solution yet.
I've tried to intercept horizontal scrolls on the the listview, but although I can intercept, it still causes the swipe to stop.
can anyone point me in the right direction ?
ViewPagers are not compatible with ListViews.
Sorry.
ViewPager inside ListView
Hi I have a problem with ListView scrolling. My activity layout:
<ScrollView>
<ReleativeLayout>
<ListView>
<... other controls>
When this list view has a lot of elements, so that they do not fit on the screen, I cannot scroll. The interesting part is that the scroll works in landscape orientation, but not in portrait.
Does any one has a suggestion on how to tweak my layout in order to allow scrolling?
Thanks
Do NOT place a listview inside a scrollview, google says it doesnt work, and every time I've tried it brings problems.
Think of this, when you swipe your finger over a the listview, what should scroll, the listview or the scrollview?
You are going to have to rethink that portion of the UI.