上周我们发布了最新的 support libraies V23.2.0
了解更多请点击:RecyclerView
这个版本给 LaiyoutManager API 添加了新的特性:自动测量(auto-measurement)!它允许 RecyclerView 根据内容控制高度。这意味着我们可以实现之前无法实现的情景(比如给 RecyclerView 设置 WRAP_CONTENT 属性)
基于这个改变,请检查 item 视图在之前设置的属性(旧版的 RecyclerView 的 item 视图如果设置 MATCH_PARENT 属性,则会自动占满整个视图)
新版的改动意味着什么呢?
举个例子:
我们使用一个简单的 item 视图填充到简单的 RecyclerView 中去:
| item_layout.xml
<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
>
<ImageView/>
<TextView/>
<TextView/>
</RelativeLayout>
之前版本(V23.1.1)
build.gradledependencies {
//...
compile ‘com.android.support:recyclerview-v7:
23.1.1’
}
新版(V23.2.0)
build.gradledependencies {
//...
compile ‘com.android.support:recyclerview-v7:
23.2.0’
}
相同的 item ,在 23.2.0 充满了整个空间,只需要修改 item 视图的 layout parameters
item_layout.xml
<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android"
android:layout_width=”match_parent”
<!-- 修改回 wrap_content -->
android:layout_height=”wrap_content” >
<ImageView/>
<TextView/>
<TextView/>
</RelativeLayout>
在 23.2.0 上给 item 设置 wrpa_content
后,RecyclerView 样式又回来了~
更多相关问题:StackOverflow
查看原文:https://medium.com/@gabri.mariotti/recyclerview-23-2-0-and-item-height-15b08eb06573#.2n9bwa1x1