简体   繁体   English

在CoordinatorLayout中的ViewPager然后在屏幕外滚动tablayout不起作用

[英]ViewPager in CoordinatorLayout then scroll tablayout offscreen not working

I have a viewpager in CoordinatorLayout like this: 我在CoordinatorLayout中有一个viewpager,如下所示:

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

and in viewpager, each fragment is a webview. 在viewpager中,每个片段都是一个webview。

The code can be run but when I scroll my webview. 代码可以运行,但滚动我的webview时。 the tablayout offscreen not working. tablayout offscreen无法正常工作。 it just at the header. 它只是在标题。

UPDATE: 更新:

I try to use relativelayout to content my views and use NestedScrollView as the relativelayout's parent but the webview disappeared(progressbar showed fine). 我尝试使用relativelayout来内容我的视图,并使用NestedScrollView作为relativelayout的父级,但webview消失了(进度条显示正常)。 Is a bug??? 是一个错误???

here is my fragment layout: 这是我的片段布局:

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minHeight="300dp">

    <ProgressBar
        android:id="@+id/pb"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:indeterminateOnly="false"
        android:max="100"
        android:progressDrawable="@drawable/progress_bar_states"></ProgressBar>

    <com.handmark.pulltorefresh.library.PullToRefreshWebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/pb" />
</RelativeLayout>

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

For those having issue with content not showing when using NestedScrollView,add "fillViewport" to xml: 对于那些在使用NestedScrollView时未显示内容问题的用户,请将“fillViewport”添加到xml:

<android.support.v4.widget.NestedScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/nestedScrollView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fillViewport="true">

Try like this: 试试这样:

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/home_coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/home_appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="2dp"
        app:paddingEnd="0dp"
        app:paddingStart="0dp">

        <include layout="@layout/toolbar_appcompat"></include>

        <android.support.design.widget.TabLayout
            android:id="@+id/home_tab_layout"
            style="@style/TabLayoutStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabContentStart="2dp"
            app:tabGravity="fill"
            app:tabIndicatorColor="@android:color/white"
            app:tabIndicatorHeight="2dp"
            app:tabMinWidth="24dp"
            app:tabMode="fixed"
            app:tabPadding="1dp"
            app:tabSelectedTextColor="@android:color/tab_indicator_text"
            app:tabTextColor="@android:color/darker_gray" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/home_view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:paddingEnd="0dp"
        app:paddingStart="0dp" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:src="@drawable/arrow_toggle"
        app:borderWidth="1dp"
        app:elevation="3dp"
        app:fabSize="normal"
        app:layout_anchor="@+id/home_coordinator_layout"
        app:layout_anchorGravity="bottom|right|end"
        app:pressedTranslationZ="2dp"
        app:rippleColor="@color/swipe_refresh_color_scheme_green" />

</android.support.design.widget.CoordinatorLayout>

It works well in my project. 它在我的项目中运作良好。

Probably the problem is with app:layout_behavior="@string/appbar_scrolling_view_behavior". 可能问题出在app:layout_behavior =“@ string / appbar_scrolling_view_behavior”。 You will find some more info here: Android - footer scrolls off screen when used in CoordinatorLayout 你会在这里找到更多信息: Android-footer在CoordinatorLayout中使用时滚动屏幕

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tablayout覆盖了CoordinatorLayout内部的viewpager - Tablayout is covering the viewpager inside the CoordinatorLayout 新的Android支持设计库,滚动tablayout offscreen无法正常工作 - New android Support Design Library, scroll tablayout offscreen not working 如果使用coordinatorLayout和tablayout,则viewPager在导航栏下展开 - viewPager is expanding under the navigationbar in case of coordinatorLayout and tablayout 滚动后折叠的工具栏,tabLayout和ViewPager无法正常工作 - Collapsing toolbar, tabLayout and ViewPager not working properly after scroll 使用Fragment和TabLayout滚动在Android ViewPager中滑动不起作用 - Swipe in android ViewPager using Fragment and TabLayout scroll not Working 具有ViewPager的TabLayout不能按预期工作 - TabLayout with ViewPager not working as expected 带有viewpager的布局无法正常工作 - Tablayout with viewpager not working ViewPager和CoordinatorLayout中的其他viewGroup无法正常工作 - ViewPager and other viewGroup in CoordinatorLayout not working 滚动在CoordinatorLayout中不起作用 - Scroll not working in CoordinatorLayout android coordinatorLayout + tabLayout(底部)+ viewPager给出错误 - android coordinatorLayout+tabLayout(bottom)+viewPager is giving error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM