我有一个带有Viewpager的Tablayout和4个片段。每个片段都有一个webview。我的问题是,每当我在片段之间滑动时,滑动并不总是准确的。如果水平滑动不准确,我会在webview上看到一个滚动条,从而阻止滑动到下一个片段。我认为这是横向和水平的问题。垂直滑动。我已经研究了一些例子,但实施起来非常复杂。请查看代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
android:fitsSystemWindows="true"
tools:context="com.example.tring.trong.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabGravity="fill"
app:tabMode="scrollable">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
这是适配器类
public class TabPagerAdapter extends FragmentPagerAdapter {
int tabCount;
public TabPagerAdapter(FragmentManager fm, int numberOfTabs) {
super(fm);
this.tabCount = numberOfTabs;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
//
Tab1Fragment tab1 = new Tab1Fragment();
return tab1;
case 1:
Tab2Fragment tab2 = new Tab2Fragment();
return tab2;
case 2:
Tab3Fragment tab3 = new Tab3Fragment();
return tab3;
case 3:
Tab4Fragment tab4 = new Tab4Fragment();
return tab4;
default:
return null;
}
}
@Override
public int getCount() {
return tabCount;
}
}
这是片段布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="false"/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/website_detail_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</WebView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>