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.
Related
I have a viewpager that inflates a layout that (sometimes) has another viewpager to view photos
<androidx.viewpager.widget.ViewPager
android:id="#+id/gallery"
android:clickable="true"
android:focusableInTouchMode="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
They both use swipes. I know there is a similar question to this, but seeing as all the answers are old and didn't work for me, does anyone know any good methods of letting users swipe the nested viewpager without forcing a swipe on the parent viewpager? I know it can be done since apps like Diaro do it, but I'm not sure how to go about it myself
I am working on a Scrollable tabs and came to observe a custom scrollable tabe in a mediaplayer app but don't know what is used in this as per my knowledge it is like scrollable tabs.Any hint how to achieve this while changing from one fragment to another .I want to show a gape in the fragment while scrolling as in this app?THIS is what I created
this is what i want a gape between two fragment
I tried to give padding in the view pager but it is not working at all.
my layout content main .xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:background="#drawable/gradient2"
>
<android.support.v4.view.PagerTitleStrip
android:id="#+id/title"
style="#style/viewPagerTitleStrip"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="top"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:background="#drawable/gradient1">
</android.support.v4.view.PagerTitleStrip>
</android.support.v4.view.ViewPager>
I tried both padding and margine in the ViewPager but it is not working
Here is the similar property used try this https://github.com/astuetz/PagerSlidingTabStrip
Since I am using ViewPager, the easiest way to achieve some space is to use the setPageMargin() method of Viewpager, which in my case will be
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setPageMargin(200);
//200 is value in pixel
There is also a method setPageMarginDrawable() sets a drawable that will be used to fill the margin between pages (Android documentation).
I have a layout in my head that should look like that: http://i.imgur.com/H1nTRvd.png
Only part that will be dynamic is the blue one. I don't know the number of tabs that will be created before I load the activity, hence the number is acquired from server (could be either 5 or 24 for all I know).
The bottom buttons should not move when I swipe and the blue area changed.
Currently I have this implemented w/o tabs list using embedded fragment in my activity and gesture listener. There's no good looking transaction animation between fragments.
#Nick Pakhomov: You can use PagerTabStrip
PagerTabStrip
is intended to be used as a child view of a ViewPager widget in your XML layout. PagerTabStrip is most often used with fragment, which is a convenient way to supply and manage the Lifecycle of each fragment.
So here’s how a ViewPager with a PagerTabStrip in it would look like in the layout file:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:id="#+id/pager_tab_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
/>
</android.support.v4.view.ViewPager>
Please check this PagerSlidingTabStrip demo . I hope it will helps you .
I want to implement a tabbed view pager where the tabs are not part of the action bar.
What is the correct way of doing this since it doesn't seem supported by standard.
So far I have been using the following approach and it seems like it's been so much more effort than it should be that it bothers me:
Create horizontally oriented linear layout to act as tab bar view
Create individual tab views to populate tab bar along with styling
Create custom ongesturelistener for left and right swipe to go between tabs
Create animations for sliding-in/out upon swiping (fragment transactions)
Create animations for the tab bar upon swiping
This seems like it's way too much work when there is a viewpager and tabbar built in. It seems though this "proper" approach is limited to only being used in conjunction with the actionbar. Can anyone provide a simple example of what I am trying to achieve? (see following picture for clarity).
You don't need to build a ViewPager bundled with an ActionBar, they are both independent views.
You can simply hide the ActionBar on that activity doing something like:
ActionBar mActionBar = activity.getActionBar();
mActionBar.hide();
Although it's an ugly solution you can do that to test your code. I would suggest either add a Theme to that specific Activity without an ActionBar (something like Theme.Material.NoActionBar) - not sure it's the correct name of the theme, but you get the idea.
Not sure I answered your question accordingly, but if not please show us some code.
You just add a viewpager with a pager tab strip. Plenty examples out there.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FragmentManager fm = getSupportFragmentManager();
fragmentPagerAdapter = new MyTabsPagerAdapter(
fm, tabsArray);
ViewPager mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(fragmentPagerAdapter);
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/default_screen_bg"
android:minWidth="1000dp">
put your image here
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.PagerTabStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingBottom="4dp"
android:paddingTop="4dp" />
</android.support.v4.view.ViewPager>
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).