How to implement a horizontal scroll / swipe between Fragments? - android

I would like to achieve a navigation in my app like Pinterest or Trello, that is, kind of three tabs to navigation + horizontal scrolling.
I have made a custom tabbar for this (since I couldn't guess how to change tabs width in my actionbar with navigation TAB mode). So I have three buttons to navigate from one fragment to another. Now I would like to implement the horizontal scrolling like these two examples, to also navigate among my fragments.
I have read about View Pager but I don't know if it fits to my case, since I don't have only views but fragments. Does anybody have an example or an idea of how to do it? Could I apply it among different activities?
Thanks

Please take a look at the duplicate question that I just answered:
How to implement a swipe-gesture between Fragments?
I suppose the Android ViewPager is what you are looking for:
http://developer.android.com/reference/android/support/v4/view/ViewPager.html
Here is a nice tutorial on how to implement it:
http://developer.android.com/training/animation/screen-slide.html
The basic idea is that you have multiple Fragments, each representing
a different Screen. The ViewPager enables the user to swipe between
the different Fragments and display different content.

You can use ViewPager. More information about viewpager this.

Related

How to combine two activities together to use it as a single feature?

I am stuck with a problem where I have designed a tab layout that I have used as a library in the current project which has a Recycler View. I want to show the tab layout on top and the recycler view under the tab layout.
For reference in Whatsapp, there is tab layout under which there is a recycler view that shows all the messages.
Problem is that I am confused about how to combine both activities together so the user can use the tab layout.
If anyone knows any solution please help!!
Use single-activity pattern. This pattern means that you need to use Fragments in a single activity (MainActivity, etc). Additional tip, you can use ViewPager2 with TabLayout for your Fragments.
Activities can't be composed into one, cause it designed so.

Nested tabs with viewpager swiping in android?

I've implemented nested tabs with view pager with no problems, but my problem is on the swiping part,
When I do the swiping action the main activity tabs will be switched, but I want the fragment to swipe instead. how can I achieve this?
I've tried implement main tab with tab host and fragment tabhost which doesn't have swiping feature at all, but that disabled whole swipe on the main and fragment together.
Instead of custom library you can try to use Bottom navigation view for bottom bar which has been added to version 25 of the Design Support Library. Here is an Article about it.
So android.support.design.widget.BottomNavigationViewin your activity together with android.support.design.widget.TabLayout and ViewPagerin fragment should work the way you want it to work. And this will also provide good UX (similar to one implemented in Google Plus App)
hello shaheen zahedi maybe it's possible please..with..below
just set bottom tab changed listener
like..
btnTab.setTabChangeListener(null);
You can disable view pager swiping on a particular ViewPager.
But I would suggest to not make 2 ViewPagers on the same screen.
Your bottom TabLayout and corresponding ViewPager can be replaced with BottomBar library.
I feel like it is wise to follow the Google Material guidelines. Not sure if you checked it out already...
Either way, here is what Google considers best practice for lateral navigation between tabs. Hope it helps!
I made a sample project with nested tab and fragment. may be it might help what is you looking for.
following link to download:
NestedTabWithFragment

How to display adjacent tabs in ViewPager?

Here is a sample from duolingo app:
I want to implement a similar feature. I can use ViewPager to make swiping tabs. What I can't seem to figure out is how to display the adjacent tabs (part of it) alongside the current tab, which is in the center.
I initially thought of implementing this using horizontal LinearLayout, but I don't know how to make the snapping effect. And it also seemed more reasonable to use something which already provides you with swiping and snapping than try to implement your own.
Using ViewPager also let's me use fragments and memory management is also effective for cases of more than a few tabs.
Any help will be appreciated. Thank You in advance.

How to display different layouts with the ViewPager?

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..:)

How can I create horizontal view scrolling like the News & Weather app?

Android News & Weather app lets you swipe to reveal another view, just like the iPhone. Can someone show me an example of how this is done?
It is not a ViewFlipper attached to a GestureDetector.
It is a custom view, you can see how it's done in Launcher by looking at Workspace.java in packages/apps/Launcher2 at android.git.kernel.org.
You can now do this out-of-the-box in the Android Compatibility library with a ViewPager: http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html?m=1
ViewPager slides between Fragments much the same way ListViews scroll up and down with views.
If you're not interested in scrolling the tabs, there's an example in the SDK that uses a TabHost (instead of making the tabs themselves scrollable left-to-right), but you need not use a TabHost. You could, if you wanted horizontally-scrolling tabs, use a HorizontalScrollView with some buttons in it.
For an approach that doesn't use the compatibility lib, or fragments, see here: https://github.com/olibye/AndroViews

Categories

Resources