RecyclerView in a ScrollView on Android 4.x, RecyclerView无法滚动
RecyclerView in a ScrollView on Android 4.x, RecyclerView can not scroll
我在ScrollView
里放了一个RecyclerView
,给RecyclerView
设置了显式高度,当我在android 5.0上运行,就可以了, RecyclerView
可以滚动,但在 4.x 上,只有外部 ScrollView
滚动。
我发现 5.0 sdk 更新了 ScrollView
源代码以支持嵌套滚动,我想了解如何使用 4.x 中的新功能。
所以我尝试将 ScrollView
更改为 android.support.v4.widget.NestedScrollView
,但仍然无效。 5.0 和 4.x 有同样的问题: RecycleView
可以滚动,但是当 RecyclerView
被触摸时,外面的 NestedScrollView
不能再滚动,除非我拖动视图没有点击事件。触摸有点击事件的视图,NestedScrollView不滚动。
然后我尝试更新support.v4
到最新版本
compile 'com.android.support:support-v4:23.1.1'
仍然使用android.support.v4.widget.NestedScrollView
代替ScrollView
,现在在5.0上运行良好,但4.x仍然存在与早期support.v4版本相同的问题
这是我的代码。外面是一个完整的 NestedScrollView,顶部是一些布局或片段,底部是一个带有片段的 ViewPager,RecyclerView 在 ViewPager 的片段中。该代码在 5.0 和 4.x.
之间具有不同的 运行ning 行为
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="hz.rrs.shop.ShopIndexActivity">
<hz.rrs.common.views.TitleView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/asi_sc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/title">
<LinearLayout
android:id="@+id/asi_ll_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/fragment4"
android:name="hz.rrs.shop.ShopHeaderFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_shop_header" />
<ImageView
android:id="@+id/asi_iv_service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:onClick="onClick"
android:scaleType="fitCenter"
android:src="@mipmap/shopindex_img_service" />
<fragment
android:id="@+id/fragment2"
android:name="hz.rrs.shop.HeadlineFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_headline" />
<fragment
android:id="@+id/fragment3"
android:name="hz.rrs.shop.PuzzleFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
tools:layout="@layout/fragment_puzzle" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/asi_ll_drag"
android:layout_marginTop="8dp">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/CustomTablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<ImageButton
android:id="@+id/asi_ibtn_contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:background="@null"
android:onClick="onClick"
android:src="@mipmap/shopindex_btn_contact"
android:layout_alignParentRight="true" />
</RelativeLayout>
问题solved.I更新sdk到新版本,一切正常
将编译 sdk 版本和构建工具版本设置为:
compileSdkVersion 23
buildToolsVersion '23.0.2'
将目标 sdk 版本设置为
targetSdkVersion 23
同时将 support.v4 更新为 23
compile 'com.android.support:support-v4:23.1.1'
然后 RecyclerView 可以嵌套滚动到 v4.NestedScrollView on 5.0 和 4.x.
所以可能是 5.x SDK 的错误。
我在ScrollView
里放了一个RecyclerView
,给RecyclerView
设置了显式高度,当我在android 5.0上运行,就可以了, RecyclerView
可以滚动,但在 4.x 上,只有外部 ScrollView
滚动。
我发现 5.0 sdk 更新了 ScrollView
源代码以支持嵌套滚动,我想了解如何使用 4.x 中的新功能。
所以我尝试将 ScrollView
更改为 android.support.v4.widget.NestedScrollView
,但仍然无效。 5.0 和 4.x 有同样的问题: RecycleView
可以滚动,但是当 RecyclerView
被触摸时,外面的 NestedScrollView
不能再滚动,除非我拖动视图没有点击事件。触摸有点击事件的视图,NestedScrollView不滚动。
然后我尝试更新support.v4
到最新版本
compile 'com.android.support:support-v4:23.1.1'
仍然使用android.support.v4.widget.NestedScrollView
代替ScrollView
,现在在5.0上运行良好,但4.x仍然存在与早期support.v4版本相同的问题
这是我的代码。外面是一个完整的 NestedScrollView,顶部是一些布局或片段,底部是一个带有片段的 ViewPager,RecyclerView 在 ViewPager 的片段中。该代码在 5.0 和 4.x.
之间具有不同的 运行ning 行为<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="hz.rrs.shop.ShopIndexActivity">
<hz.rrs.common.views.TitleView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/asi_sc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/title">
<LinearLayout
android:id="@+id/asi_ll_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/fragment4"
android:name="hz.rrs.shop.ShopHeaderFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_shop_header" />
<ImageView
android:id="@+id/asi_iv_service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:onClick="onClick"
android:scaleType="fitCenter"
android:src="@mipmap/shopindex_img_service" />
<fragment
android:id="@+id/fragment2"
android:name="hz.rrs.shop.HeadlineFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_headline" />
<fragment
android:id="@+id/fragment3"
android:name="hz.rrs.shop.PuzzleFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
tools:layout="@layout/fragment_puzzle" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/asi_ll_drag"
android:layout_marginTop="8dp">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/CustomTablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<ImageButton
android:id="@+id/asi_ibtn_contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:background="@null"
android:onClick="onClick"
android:src="@mipmap/shopindex_btn_contact"
android:layout_alignParentRight="true" />
</RelativeLayout>
问题solved.I更新sdk到新版本,一切正常
将编译 sdk 版本和构建工具版本设置为:
compileSdkVersion 23
buildToolsVersion '23.0.2'
将目标 sdk 版本设置为
targetSdkVersion 23
同时将 support.v4 更新为 23
compile 'com.android.support:support-v4:23.1.1'
然后 RecyclerView 可以嵌套滚动到 v4.NestedScrollView on 5.0 和 4.x.
所以可能是 5.x SDK 的错误。