[英]Swipe in android ViewPager using Fragment and TabLayout scroll not Working
I added the new Toolbar
, Tablayout
and Viewpager
in my android app. 我在Android应用程序中添加了新的Toolbar
, Tablayout
和Viewpager
。 I want to create a swipe application for this I am using ViewPager
. 我想为此使用ViewPager
创建滑动应用程序。 swipe and Tablayout
scroll is not working on this. 滑动, Tablayout
滚动对此不起作用。
main.xml 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
. 当我更改DrawerLayout
和TabLayout
位置时, DrawerLayout
变为隐藏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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.