一个android新手在这里:-)我正在学习材料设计的CoordinatorLanyout。因此,我尝试在CoordinatorLanyout中实现TabLayout,它工作得很好。但我在ViewPager的一个片段中实现了RecyclerView,并遇到了一个奇怪的滚动问题。列表现在不能滚动。我在网上冲浪,尝试了很多解决方案,但都不能解决这个问题。这是我的activity_main.xm
<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
<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
<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文件。
执行这些操作后,滚动就不起作用了。
发布于 2016-04-11 15:54:02
您的结构应该是这样的->
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
<Layout/>
<Toolbar/>
</CollapsingToolbarLayout>
<TabLayout/>
</AppBarLayout>
<ViewPager/>
</CoordinatorLayout>我想你会理解的。
https://stackoverflow.com/questions/36542683
复制相似问题