How to show all the tabs in viewPager at time

134 views Asked by At

I'm using viewPager that has a fragment and that fragment has a recyclerView. I'm trying to display all the tabs of viewPager at the same time. Is that possible or there is any different approach to deal with the situation.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:tabGravity="center"
            android:layout_gravity="center_horizontal"
            app:tabMode="scrollable"
            app:tabPaddingEnd="1dp"
            app:tabPaddingStart="1dp"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" /> 
</LinearLayout>
1

There are 1 answers

4
Ezzy On

If you want to display all data from each tab at once I would suggest not using ViewPager, because that kind of ruins the purpose of it.

If your idea is to separate how the data is presented depending on screen size and/or orientation, then you could load a different view like so:

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
    //Load landscape view with all data displaying at once
    setContentView(R.layout.main_landscape);
}
else
{
    //We're in portrait mode, so we don't have space to fit all data at once
    //so here we can take use of the ViewPager.
    setContentView(R.layout.main_portrait);
}