Jump instantly with ViewPager - java

I have a tabbed ViewPager which lets the user jump to the corresponding page depending on which tab they press. The problem is that you see the view pager scroll really quickly to the selected page, meaning you get small glimpses of each its scrolls through. Is there a way to stop this and jump instantly without seeing other pages.

Call setCurrentItem(itemPosition, false) on your ViewPager instance. As per the documentation the second parameter is smoothScroll effect which causes the glimpses of the other fragments.

Related

ViewPager: onPageSelected not being call if user swipe below or equal 50% of a screen

I have a Viewpager that show a list calendar of month and when I try to swipe each tab sometime it's hard to go to another tab like when user have to scroll to another page there is 2 possibility:
User have to swipe fast so it will work fine
If user scroll slowly, they have to move the page larger than 50% of the screen to move next or right
So in the second case it make my user hard to swipe between each tab because it take a bit longer just to move between each tab
In recycler view user don't need to swipe larger than 50% of the screen to move the page though

How to prevent stopping setCurrentItem() on program start?

Helo,
I've got a ViewPager with some thousand pages. It scrolls to page 5000 at program start with the method setCurrentItem(5000).
My problem is:
When I start application and tap quickly on the screen, then setCurrentItem(5000) doesn't work. It stops at the first item.
How can I prevent this?
Try using setCurrentItem(5000, false). The second parameter is smoothScroll, which is true by default. If you set it to false, the ViewPager will "transition immediately" to the View.
You can refer to the documentation for this.

Showing pagerSlidingTabStrip on the layout without viewPagerAdapter on Android 5.0+

I would like to develop an android app's UI looks like the Uber's but booking rooms.
I want to implement the function about showing the option's description, from users who are clicking the PagerSlidingTabStrip items which shown on the bottom. The fragment page will be shown when the user click the fragment tab (PagerSlidingTabStrip), also the chosen option will be selected.
I feel puzzled and confused when I am implementing this function, and concern the pagerSlidingTabStrip can trigger events by setOnClickListner or not. Also I don't willing to show the fragment page on the main page once users logged on the page by default.
Thank you.
Its better if you use TabLayout instead of PagerSlidingTabStrip
That will help you to get click of the Tab selected as well as reselected and on that click event you can hide and show your Bottom Views which holding fragments

Keyboard hides content in fragment, I need the frame layout to resize so bottom is just above the keyboard and now scrollable

I have a fragment in my app that has a scroll view for the signup and login pages. Right now there isn't enough content in the scroll view to actually make it scroll, however when the keyboard appears, it does cover up most of the content in the view. This causes a lot of issues especially on devices with smaller screens, it blocks a lot, and the view is NOT scrollable, so I have to close the keyboard to get to the rest of the inputs.
I need the bottom of the fragments frame layout to be pushed up to JUST above the top of the keyboard, so the keyboard won't actually hide any content, and still allow the scroll view to actually scroll to the rest of the content.
I have seen the usual fix to an issue similar to this, which would to change the AndroidManifest.xml to the following:
android:windowSoftInputMode="adjustResize"
but this will push up the entire page, which includes the footer view I have under and outside of the login and signup fragment layouts. It makes my scrollview smaller and allows for it to scroll, but I need the footer to stay hidden under the keyboard still.
I think a work around to this would be to have override onConfigurationChanged(); in MyActivity that will detect if the keyboard has appeared, and if it has, push the bottom of the framelayout to be JUST above the keyboard, thus making the scroll view smaller, and allowing us to actually scroll. I am not quite sure HOW to do this though.
Here is what it looks like with the keyboard up, blocking the content. This would be okay IF the scroll view was scrollable, allowing me to see the rest of the content, however it will not scroll and the only way to access the content under it is to close the keyboard first.
EDIT
I was able to use the answer below, editing the Android manifest for
android:windowSoftInputMode="adjustResize"
and the first method using the code below
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
I had it adjust my views so the footer would be pushed way down below, then resize the layout holding the fragment to extend down allowing it to be scrollable still.
Okay, here's how I solved it.
The basic idea is that you have to:
Detect whether or not a soft-keyboard is showing,
React. Based on the detected information (is-soft-keyboard-showing), resize your layout accordingly.
There are two ways of achieving this:
to give your activity's root view a known ID, say '#+id/activityRoot', hook a GlobalLayoutListener into the ViewTreeObserver, and from there calculate the size diff between your activity's view root and the window size:
Customize your top-level layout class into one which overrides onMeasure()
And I would like to credit the above answer to this SO Post: how-to-check-visibility-of-software-keyboard-in-android, which I have found earlier on this particular problem.

Scrollable PagerTabStrip

I've been searching for this topic for a while, and can't find enough resources or tuts about scrolling a PagerTabStrip. I'm using the FragmentStatePagerAdapter and populates the PagerTabStrip with getPageTitle(int position). I'd like to know how to make the titles scrollable. I'd like to scroll the titles without affecting the view by the time I stop or select into a specific title, then that's the time the view gets updated. I've been thinking to use HorizontialListView but not sure how to start. Hoping to learn from you. Thanks.
Found this on docu:
PagerTabStrip is an interactive indicator of the current, next, and
previous pages of a ViewPager. It is intended to be used as a child
view of a ViewPager widget in your XML layout. Add it as a child of a
ViewPager in your layout file and set its android:layout_gravity to
TOP or BOTTOM to pin it to the top or bottom of the ViewPager. The
title from each page is supplied by the method getPageTitle(int) in
the adapter supplied to the ViewPager.
I been searching on this on the web, but I didn't get any relevant resources. I just found out another library called actionsherlock that enables the scrolling of tabs without affecting the view which is exactly what I need, instead of using PagerTabStrip's listener .
I'm also searching for the same thing. Too bad you have to make your own implementation or use third-party library. I have read that this library offer the feature of scrolling tab independent of the content. But I have not tried it out yet.
http://viewpagerindicator.com/?utm_source=androidweekly&utm_medium=toolbox
Do you actually mean the ActionBarSherlock? Do you have an example?

Categories

Resources