I want Horizontal as well as vertical swipe using the ViewPager.I implemented it using the Vertical view pager in which I used the fragments for the vertical swipe and in that fragments, used ViewPager for the horizontal swipe.
I took help from below link for vertical swipe:
https://github.com/LambergaR/VerticalViewPager/
and http://manishkpr.webheavens.com/android-viewpager-as-image-slide-gallery-swipe-gallery/ for horizontal swipe.
Problem:
I have three image adapters and three fragments, one for each image adapter. These three fragments are inside one FragmentActivity. When this FragmentActivity is created I want to manually select which fragment should be displayed. Here, the three fragments contains data with three different languages. Now I want to load the fragment of particular language specified by the user. Any example or a code snippet will help me implement this functionality.
Thanks in advance :)
Related
I am facing a situation as of few days now. I intend to create an activity where there is a TabLayout and a ViewPager.
The tabs in TabLayout corresponds with the fragments/slides in the ViewPager.
Now as of now, each fragment contains the same format,i.e., two TextViews, one under the other, populated with the strings softcoded in string.xml
But this resulted in the creation of too much xml files for the fragments used inside ViewPager.
So I was thinking if it's possible to use only one fragment inside the ViewPager and then programmatically set the strings for those two TextViews in the fragment, that changes each time w.r.t. click on another tab or sliding on the ViewPager area.
This will lessen the no. of fragments to only one, in turn cutting the time to create it and increase the overall performance of the app in which it will be present.
So any insightful help, suggestion, or walkthrough on how to implement this concept - any help on how to do this will be highly appreciated.
You can certainly do that. If you're using FragmentStatePagerAdapter, just initiate the same fragment with different arguments supplied according to it's position and then in fragment check for those arguments and make changes accordingly.
Lets keep it really simple. Say I created 4 layout's called page_one, page_two, page_three, page_four. How can you make it so you can swipe through all those pages back and forth horizontally?
You can use a View Pager to achieve this.
you can swipe through the pages by using a view pager.
you can go through this link
http://developer.android.com/training/animation/screen-slide.html
Edit:
1) Create 4 layouts for 4 fragments view.
2) Create a activity which extends FragmentActivity.
3) Create an adapter for view pager and set the adapter in your main method.
4) You can use tabs also for this.
I have an activity. Inside that activity I have implemented VerticalViewPager in which 3 pages are fed i.e. Upper Page, Middle page and Lower Page. Inside the middle page fragment and Lower page fragment I have separately another ViewPagers(Horizontal).Inside these ViewPagers I have 3/3 pages each. So far I have been able to make them working just fine i.e. on vertical swipe gesture the VerticalViewPager gets triggered and on horizontal swipe gesture native android ViewPager gets triggered. Now I need to sync the horizontal swipe transition between the middle fragment pages and lower fragment pages.
Let me give an example: say I have A,B and C pages inside middle fragment of VerticalViewPager and D,E,F inside the lower vertical fragment. Assume I am in the middle fragment now. So when I swipe from A to B left to right, the lower fragment should also swipe from D to E automatically.
[P.S.: For the horizontal(native) ViewPager to work inside
VerticalViewPager, the horizontal ViewPager Adapter needs to run
in the AsyncTask or threads. So please consider this scenario as
well]
You can make the adapter scope available globally and set the current view or fragment according to the change in the middle fragment.
According to the example:
In Xamarin, I currently have two different activities and I would like to combine these together and use a ViewPager.
One activity uses the following content view: SetContentView(Resource.Layout.MapWithOverlayLayout);
The second activity uses the following content view: SetContentView(Resource.Layout.HomeScreen);
Can I please have some help to code a simple ViewPager that can add the two above content views into a ViewPager and then show each of these content views via code?
Thanks in advance
For a ViewPager, you will need Fragments instead of Activities.
Here is how to implement a ViewPager with Fragments and different layouts: How to implement a ViewPager with different Fragments / Layouts
The basic idea is that you create a Fragment for every layout you have, and then inside your FragmentPagerAdapter, load the correct Fragment depending on which page you are currently on.
This is how I am doing it in my other post and sorry about not posting the same code here.
Take a look at those links. It will help for sure.
Android:How to create different view in ViewPager?
Its a pretty simple implementation. You can define your own layouts and then use it in the view pager.
Here's my other post where you can get what you want to achieve:
How to use swipe gesture in a view pager's page with android?
Hope this helps..:)
I have seen lots of examples of how to use a ViewPager to scan through multiple instances of the same Fragment. I don't want to do that. I want to have a single instance of a Fragment that runs off the edge of a screen and use a ViewPager (or at least the nice clean ViewPager swiping effect) to scan through the different sections of the single fragment. Is this possible?
Is this possible?
You can:
Use nested fragments for the pages in ViewPager, or
Use views for the pages in ViewPager, such as in this sample app, or
Use HorizontalScrollView instead of ViewPager to wrap around a single wide view