简体   繁体   中英

Swipe in android ViewPager using Fragment and TabLayout scroll not Working

I added the new Toolbar , Tablayout and Viewpager in my android app. I want to create a swipe application for this I am using ViewPager . swipe and Tablayout scroll is not working on this.

main.xml

<RelativeLayout
    android:id="@+id/main_layout"
    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.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/toolbar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">


        <Spinner
            android:id="@+id/customspinner"
            android:layout_width="180dp"
            android:layout_height="46dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@color/toolbar"
            android:layout_gravity="right"
            android:dropDownWidth="500dp"
            android:dropDownVerticalOffset="100dp"
            />


    </android.support.v7.widget.Toolbar>


    <android.support.design.widget.TabLayout
        app:tabMode="scrollable"
        android:id="@+id/tab_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:background="@color/list_background"
        android:elevation="10dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>


        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_below="@id/tab_layout"/>


    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">


        <FrameLayout
            android:id="@+id/frame_container1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <ExpandableListView
            android:id="@+id/list_slidermenu"
            android:layout_width="360dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/list_background"
            android:choiceMode="singleChoice"
            android:dividerHeight="1dp"
            android:divider="@android:color/darker_gray"
            android:groupIndicator="@null" >
        </ExpandableListView>


    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

DrawerLayout goes hide When I change place of DrawerLayout and TabLayout .

Thank You.

Did you use this?

// Setting the ViewPager For the SlidingTabsLayout
    tabs.setViewPager(pager);

You have to add this to change tabs with page and vice versa.

    viewPager.addOnPageChangeListener(newTabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setTabsFromPagerAdapter(mAdapter);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM