【发布时间】:2016-12-05 08:25:29
【问题描述】:
我遇到了一个奇怪的问题。我有一个带有两个 RecyclerView 的 xml 和一个带有 NestedScrollview 内的圆形页面指示器的 ViewPager。我使用 layout_weight 和 weightSum 在屏幕上显示小部件。 RecyclerView 之一具有水平布局,可以很好地水平滚动。我想实现单垂直滚动,但不幸的是它不起作用。
我在 xml 中使用了“app:layout_behavior="@string/appbar_scrolling_view_behavior”,在 java 代码中使用了“recyclerview.setNestedScrollingEnabled(false)”。
这是我的 fragment_home.xml
<android.support.v4.widget.NestedScrollView 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:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.e2e.qnamo.fragment.HomeFragment">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
android:descendantFocusability="blocksDescendants">
<include
layout="@layout/layout_pager_indicator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_hot_topic"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:layout_weight="2"
tools:listitem="@layout/hot_topic_row" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_category"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:layout_weight="5"
tools:listitem="@layout/category_row"/>
</LinearLayout>
这是我的 layout_pager_indicator.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/bannerViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/viewpager_indicator_single_item" />
<com.e2e.qnamo.widget.CirclePageIndicator
android:id="@+id/pager_indicator"
style="@style/CustomCirclePageIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_gravity="center|bottom"/>
【问题讨论】:
标签: android android-viewpager android-recyclerview viewpagerindicator nestedscrollview