您的位置:首页 > 移动开发 > Android开发

Android 6.0 解决Recyclerview 在 Scrollview 中不能高度自适应问题

2016-10-17 20:32 736 查看

Android 6.0 解决Recyclerview 在 Scrollview 中不能高度自适应问题

在项目中遇到解决Recyclerview 在 Scrollview 中不能高度自适应问题:android6.0以下机器是可以的,但是6.0就不能自适应,经网上查询应该是一个bug。

在网上查询资料终于找到解决方法

http://stackoverflow.com/questions/27083091/recyclerview-inside-scrollview-is-not-working

其他网站重写LayoutManager的方法试了都不行。

最终解决办法很简单,如下:

在 recyclerview 外面再嵌套一层 RelativeLayout即可。

代码 如下:

xml

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@null"
android:fadingEdge="none"
android:listSelector="@android:color/transparent"
android:padding="@dimen/margin_horizontal_mid"
android:scrollbarStyle="outsideOverlay"
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="4"
tools:listitem="@layout/adapter_repair_image_list_item" />
</RelativeLayout>


activity:

private void initWidget() {
selImageList = new ArrayList<>();
adapter = new ImagePickerAdapter(this, selImageList, maxImgCount);
adapter.setOnItemClickListener(this);

mRecyclerViewImage.setLayoutManager(new GridLayoutManager(this, 4));
mRecyclerViewImage.setHasFixedSize(true);
mRecyclerViewImage.setAdapter(adapter);
}


以上方法亲测可用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android android6-0
相关文章推荐