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).
Related
I want to use a vertical slide on my application so i implemented this library:
https://github.com/castorflex/VerticalViewPager
by adding implementation com.github.castorflex.verticalviewpager:library:19.0.1
in the dependencies of build.gradle.
Now i want to add this viewPager to my xml file (If it was native horizontal View pager i'll do in the layout something like <android.support.v4.ViewPager>)
But everything i try failed, what is the syntax to do it ? (never worked with libraries before)
I've tried <github.castorflex.verticalviewpager> too
Thanks
You have to put in your xml
<fr.castorflex.android.verticalviewpager.VerticalViewPager
android:id="#+id/verticalviewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
In this page Google explicitly said TabLayout can be integrated into ViewPager in layout xml file.
ViewPager integration
If you're using a ViewPager together with this layout, you can call
setupWithViewPager(ViewPager) to link the two together. This layout
will be automatically populated from the PagerAdapter's page titles.
This view also supports being used as part of a ViewPager's decor, and
can be added directly to the ViewPager in a layout resource file like
so:
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</android.support.v4.view.ViewPager>
However, whatever I tried, I cannot make TableLayout appears. Separate both is fine. I wonder is this actually working??
I don't think TabLayout works as a ViewPager child as they claim.
Any view that wants to be a child of ViewPager has to set a boolean layout param property specific to ViewPager called isDecor. I just looked through the source code and I don't see any place where either the ViewPager or TabLayout set this layout param property.
I think it was something they meant to do and either a) they never did it or b) there was an issue so they took it out. Just use the TabLayout outside ViewPager, there's no real benefit to having it be a decor view.
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
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
The latest Android Support Library introduced the DrawerLayout to implement the common UX pattern where you slide right or left to show a navigation menu.
What I'd love to have is a vertical DrawerLayout with the same API, that can be pulled down/up from the top/bottom of my layout.
Since 4.2 the old SlidingDrawer has been deprecated and I haven't heard about some new Widget that implements the same functionality.
Can the DrawerLayout be extended somehow to implement the vertical swipe UX pattern?
Does google provide some different widget to implement it?
Google Music for instance has something very similar to what I'm looking to implement to pull up the player.
We have recently implemented this in the Umano App and open sourced: https://github.com/umano/AndroidSlidingUpPanel
Enjoy.
The Android support library now has the bottom sheets behavior to do that.
Check out this link for more info https://material.google.com/components/bottom-sheets.html
Nowadays, it makes more sense to use the BottomSheetBehavior that you can find more information on how setting it up on https://code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031
Basically, you need to set your main content, and your sliding content. The BottomSheetBehavior would only work for panels that you slide from the bottom to the top.
It has a quite simple set up and the BottomSheetBehavior could even work out of the box. Only by writing a android.support.design.widget.CoordinatorLayout layout, with another View inside (with even wrap_content as a value in the layout_height parameter), for instance a LinearLayout like this one:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="56dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<!-- Your content goes here -->
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
In my case, I inflate this layout in a Fragment and add it to the Activity where you want to enable the SlidingSheetBehavior.