首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ViewPager显示CoordinatorLayout中的滚动问题

ViewPager显示CoordinatorLayout中的滚动问题
EN

Stack Overflow用户
提问于 2016-04-11 15:43:47
回答 1查看 699关注 0票数 0

一个android新手在这里:-)我正在学习材料设计的CoordinatorLanyout。因此,我尝试在CoordinatorLanyout中实现TabLayout,它工作得很好。但我在ViewPager的一个片段中实现了RecyclerView,并遇到了一个奇怪的滚动问题。列表现在不能滚动。我在网上冲浪,尝试了很多解决方案,但都不能解决这个问题。这是我的activity_main.xm

代码语言:javascript
运行
复制
 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:local="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        android:elevation="8dp"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="20dp"
        app:expandedTitleMarginEnd="10dp">

        <include
            android:id="@+id/counter_id"
            layout="@layout/counter_layout"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:elevation="8dp"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:layout_collapseMode="pin"/>


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

 <android.support.design.widget.TabLayout
            android:id="@+id/pager_tab_id"
            android:background="@color/colorPrimary"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:layout_gravity="bottom"
            app:tabMode="scrollable"/>

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

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

这里是用于替换片段的框架布局。因此viewpager将获取此帧容器。

我使用这个xml来设置viewPager布局,它将使用我上面提到的activity_main.xml中的FrameLayout

代码语言:javascript
运行
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="bodhi.electionpoll.ui.fragment.PanchayathHistoryFragment">

<android.support.v4.view.ViewPager
    android:id="@+id/content_panchayath_hisory_pager"
    android:background="@color/windowBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

接下来,我为RecyclerView适配器设计了一个xml

代码语言:javascript
运行
复制
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe_container_service"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">


<SearchView
    android:id="@+id/search"
    android:visibility="gone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:textSize="16sp"
    android:hint="Search here"/>
<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_list"
    android:layout_below="@+id/search"
    android:layout_width="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:fillViewport="true"
    android:layout_marginTop="4dp"
    />
</RelativeLayout>

我认为没有必要提及相关的java文件。

执行这些操作后,滚动就不起作用了。

EN

回答 1

Stack Overflow用户

发布于 2016-04-11 15:54:02

您的结构应该是这样的->

代码语言:javascript
运行
复制
    <CoordinatorLayout>
        <AppBarLayout>
            <CollapsingToolbarLayout>
                 <Layout/>
                 <Toolbar/>
            </CollapsingToolbarLayout>
          <TabLayout/>
        </AppBarLayout>
     <ViewPager/>
  </CoordinatorLayout>

我想你会理解的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36542683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档