Как показать все вкладки в ViewPager одновременно - PullRequest
0 голосов
/ 05 ноября 2018

Я использую viewPager, у которого есть фрагмент, а у этого фрагмента recyclerView. Я пытаюсь отобразить все вкладки viewPager одновременно. Это возможно, или есть другой подход к ситуации.

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 Ответ

0 голосов
/ 05 ноября 2018

Если вы хотите отобразить все данные с каждой вкладки сразу, я бы предложил не использовать ViewPager, потому что такой вид разрушает его цель.

Если ваша идея состоит в том, чтобы разделить представление данных в зависимости от размера экрана и / или ориентации, вы можете загрузить другое представление, например, так:

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);
}
...