android ViewPager swipe both direction - android

I want to swipe view pager in both direction with infinite rotations.
For example
When swipe right then 1->2->3->1->2. So on
When swipe left then 1->3->2->1->3. So on

There is a library maybe help you
dependencies {
compile 'com.antonyt.infiniteviewpager:library:1.0.0'
}
In your layout
<com.antonyt.infiniteviewpager.InfiniteViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
In your code, wrap your existing PagerAdapter with the InfinitePagerAdapter
PagerAdapter wrappedAdapter = new InfinitePagerAdapter(adapter);
viewPager.setAdapter(wrappedAdapter);
But this library just working when you have at least 4 pages. More info link github library

Related

Implementing Carousel with PageViewer in Android

I am trying to implement a carousel (the kind with the dots on the bottom to show the number of items / pages and the current selected item) using PageViewer.
The swipe part is working fine, but the indication that there a further content available was missing.
I tried using PagerTabStrip and PagerTitleStrip but they are showing the page title, but I want to show the dots.
I have read about a few libraries which provide the functionality but am trying to avoid using those.
Please let me know if there is a way I can extend my current code to accommodate it
EDIT
the updated layout code is as follows
`
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_graph_pager"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_marginTop="5dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.vivekji.munimji.activity.TabGraph">
<me.relex.circleindicator.CircleIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="48dp" android:background="#fff"/>
</android.support.v4.view.ViewPager>
`
Use CirclePageIndicator along with ViewPager
1. Add gradle dependency
dependencies {
compile 'me.relex:circleindicator:1.2.2#aar'
}
2. Use CircleIndicator in your layout
<me.relex.circleindicator.CircleIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="48dp"/>
3.Set up indicator with viewpager
ViewPager viewpager = (ViewPager) view.findViewById(R.id.viewpager);
CircleIndicator indicator = (CircleIndicator) view.findViewById(R.id.indicator);
viewpager.setAdapter(mPageAdapter);
indicator.setViewPager(viewpager);

Design support library Tablayout Sliding abnormal

I'm learning to use Tablayout,but I found that the Tablayout can not slide normal.The tab slides with my gesture.The question is that
When I stop gesture, it will stop immediately, and does not automatically slide to the next tab.
the layout:
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The code:
SimpleFragmentPagerAdapter adapter = new SimpleFragmentPagerAdapter
(getSupportFragmentManager(), this);
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
When I had this happen to me, it was because either 1) My adapter didn't properly create a fragment for that page, or 2) The fragment didn't properly create a view for the page.
Use a tool like Android Device Monitor to check the view on the viewpager and see if it is there as you expect, and that it is not zero width.

How to achieve a custom layout with next page title shown half, indicating the user of next page as shown in android

FIRST PAGE
[/IMG]
SECOND PAGE
[/IMG]
I want show my two pages like this, When loading first page the second page title should be shown indicating the user about a second page. How can I achieve this?, I can put two tabs or viewpager with view pager indicator, i want that functionality but actually what I ask here is the view that is marked the image, the next tab to display half of its title indicating the user of next page.
Thanks in advance..
You can directly use ViewPager with PagerTabStrip provided in android support-v4 library.
Download android Support-V4 library here
Then extract the android Support-V4 jar and paste into your project libs Folder.
Right click and Add to build path.
Now use View pager with PagerTabStrip in your Main layout as:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="#+id/viewpage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/pagetab"
>
<android.support.v4.view.PagerTabStrip
android:id="#+id/pagetab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#333333"
android:background="#ffffff"
android:layout_gravity="top"/>
</android.support.v4.view.ViewPager>
</RelativeLayout>
Now populate the ViewPager using Adapter in Main Class .see here
Now you can Achieve What you want.
I strongly advise you to use a library, instead creating the widget yourself.
That said, this library suit your requirements. It’s really easy to implement it:
PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(yourViewPager);
You can found a complete implementation here

Viewpager Vertical

I'm trying to make default viewpager use vertical scrolling. And I'm stuck. I tried using Directional ViewPager
but it's kinda buggy and very laggy with vertical ori
Then i tried VerticalViewPager but i don't know how to use that. Replacing normal viewpager doesn't work. Any ideas how to implement Vertical View pager?
Edit: I also tried vertical view pager but this one working only in Android Studio, dunno how to use it in Eclipse, should i import project as a lib? or compile it to jar file and import as a lib?
Implementation of the compatibility library ViewPager class that supports paging both vertically and horizontally.
but you can choose to use a lib
Android-DirectionalViewPager
For a working implementation of this project see the sample/ folder.
Include the widget in your view.
<com.directionalviewpager.DirectionalViewPager
android:id="#+id/pager"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
By default the widget will page horizontally. You can alter this behavior by including android:orientation="vertical" in the layout or by calling setOrientation(DirectionalViewPager.VERTICAL) in your code.
In your onCreate method (or onCreateView for a fragment), bind to a PagerAdapter implementation.
DirectionalViewPager pager = (DirectionalViewPager)findViewById(R.id.pager);
pager.setAdapter(new TestAdapter(getSupportFragmentManager()));
ViewPager-Android
ViewPager, Based on the Android support library's ViewPager class, this ViewPager supports both horizontal and vertical paging views.
This ViewPager is a drop in replacement for the support library version. Simply reference the library and replace your ViewPager imports with this version.
Reference in your XML like this.
<com.ryanharter.viewpager.ViewPager
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:orientation="vertical"/>
Notice that you can use app:orientation="vertical" to easily set the orientation of the ViewPager to vertical. Orientation defaults to horizontal.
You can also set orientation in code using
mViewPager.setOrientation(ViewPager.ORIENTATION_VERTICAL).

ViewPagerIndicator's TitlePageIndicator stopping fragments from showing and causing swiping to not work

I'm seeing a very strange error when trying to use ViewPagerIndicator (http://viewpagerindicator.com/). I've narrowed it down to the TitlePageIndicator that is part of that library.
When I use the TitlePageIndicator, I am unable to swipe between tabs, and my fragments don't show up (although they are created and ran, the button in the upper right is created by the fragment that should be showing). It looks like this: http://imgur.com/RJaI9 (Sorry, new user so I can't inline pictures)
But without, my fragments appear correctly and I'm able to swipe between them. http://imgur.com/bboSd
I have no idea why this is happening. I'm using the latest ViewPagerIndicator library, but I'm thinking maybe it has something to do with how I imported it? I followed the instructions on the website:
created the new android project in eclipse from existing source, imported the compatibility library, then added it to my project in the android project properties.
Any help would be greatly appreciated, I've been stuck on this for 2 weeks :(
Code:
Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.viewpagerindicator.TitlePageIndicator
android:id="#+id/titles"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="#+id/grocery_pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
FragmentActivity (From ActionBarSherlock):
public class GroceryActivity extends BaseFragmentActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grocerylist);
// Set the pager with an adapter
ViewPager pager = (ViewPager) findViewById(R.id.grocery_pager);
pager.setAdapter(new GroceryViewPagerAdapter(getSupportFragmentManager()));
// Bind the title indicator to the adapter
//When these next two lines are commented out, everything works
TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
titleIndicator.setViewPager(pager);
}
}
I ended up finding the problem:
In my linear layout, I did not set the orientation of the layout. For some silly reason I thought the orientation field had to do with the orientation of the device, and not the layout itself. Adding the orientation:vertical field made everything work.
Hopefully this helps someone!

Categories

Resources