【发布时间】:2016-04-11 07:43:47
【问题描述】:
一个安卓新手来了 :-) 我正在学习材料设计中的 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文件不用提了
在实施这些之后, 滚动不起作用
【问题讨论】:
标签: android android-viewpager android-recyclerview android-tablayout android-coordinatorlayout