RecyclerView 23.2.0新特性

来源:互联网 发布:淘宝网羽绒棉裤女 编辑:程序博客网 时间:2024/06/05 08:25

这个版本给LayoutManager API添加了新的特性:自动测量(auto-measurement)! 他允许RecyclerView 根据内容控制高度。这意味着我们可以实现之前无法实现的情景(比如给 RecyclerView 设置 WRAP_CONTENT 属性)


新版的改动意味着什么呢?
举个例子:

我们使用一个简单的 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.gradle
dependencies {
    //...
    compile ‘com.android.support:recyclerview-v7:23.1.1’
}

新版(V23.2.0)

build.gradle
dependencies {
//...
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></textview></textview></imageview></relativelayout>

在 23.2.0 上给 item 设置 wrpa_content 后,RecyclerView 样式又回来了~

结束了吗?还没完呢

在这补充一下在23.2版本之前使用wrap_content是不起效果的,recycleview这个布局还是会占满屏幕的,所以更新到最新版本吧!


1 0
原创粉丝点击