Android RecyclerView 在8.0以上手机和华为手机上卡顿

rooman 发布于 2018/11/05 17:04
阅读 539
收藏 0

最近我发现在oppo android 8.1 的手机上 元素过多的item, 滑动出现卡顿。快速滑动的时候,前几个item会顿一下,然后后面的item正常滑动 。视觉上出现刚开始顿一下的情况。浏览过的item,再次快速滑动是没有卡顿情况的。
下面给出 布局文件,测试的时候复制下面的布局文件,什么都不需要做,Adapter里面什么都不用做,只需要模拟一下数据,然后滑动默认布局就可以看到卡顿情况(在低版本的手机上暂时没看到卡顿,目前就8.1的手机和华为手机上看到明显卡顿) 。烦请大神查看有没有什么方案可以解决卡顿情况。谢谢~

buildToolsVersion "26.0.2"
recyclerView 的版本是26.1.0,

我的(Item)布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/_f2f2f2">

    <View
        android:id="@+id/headerDivider"
        android:layout_width="match_parent"
        android:layout_height="10dp"/>

    <!--左边正常布局-->
    <include
        android:id="@+id/normalLinear"
        layout="@layout/layout_item_vertical_normal_first_demo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="12dp"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/mid"
        app:layout_constraintTop_toBottomOf="@id/headerDivider"/>

    <View
        android:id="@+id/mid"
        android:layout_width="12dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="@+id/normalLinear2"
        app:layout_constraintLeft_toRightOf="@id/normalLinear"
        app:layout_constraintRight_toLeftOf="@+id/normalLinear2"
        app:layout_constraintTop_toBottomOf="@id/headerDivider"/>

    <!-- 右边正常布局 -->
    <include
        android:id="@+id/normalLinear2"
        layout="@layout/layout_item_vertical_normal_second_demo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="12dp"
        app:layout_constraintLeft_toRightOf="@id/mid"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/headerDivider"/>


</android.support.constraint.ConstraintLayout>

 

<layout_item_vertical_normal_first_demo>

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_vertical_goods_all_radius">

    <com.makeramen.roundedimageview.RoundedImageView
        android:id="@+id/goodsImg"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scaleType="fitXY"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:riv_corner_radius_top_left="4dp"
        app:riv_corner_radius_top_right="4dp"/>

    <TextView
        android:id="@+id/specialCount"
        android:layout_width="50dp"
        android:layout_height="22dp"
        android:ellipsize="end"
        android:gravity="center"
        android:background="@drawable/bg_grid_goods_special_count"
        android:minWidth="50dp"
        android:singleLine="true"
        android:text="@string/special_count"
        android:textColor="@color/white"
        android:textSize="@dimen/_11sp"
        android:visibility="gone"
        app:layout_constraintRight_toRightOf="@id/goodsImg"
        app:layout_constraintTop_toTopOf="@id/goodsImg"/>

    <View
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="102dp"
        android:background="@drawable/bg_vertical_normal_goods_bom_radius"
        app:layout_constraintTop_toBottomOf="@id/goodsImg"/>

    <ImageView
        android:id="@+id/delivery_free"
        android:layout_width="22dp"
        android:layout_height="12dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="12.5dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@id/content"/>

    <TextView
        android:id="@+id/goodsTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:ellipsize="end"
        android:gravity="left"
        android:includeFontPadding="false"
        android:maxLines="2"
        android:text=""
        android:textColor="@color/_333333"
        android:textSize="@dimen/_15sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@id/content"/>

    <TextView
        android:id="@+id/couponValue"
        android:layout_width="53dp"
        android:layout_height="19dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="50dp"
        android:background="@drawable/bg_coupon_number"
        android:gravity="center"
        android:text="20元券"
        android:textColor="@color/white"
        android:textSize="@dimen/_12sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@id/content"/>

    <TextView
        android:id="@+id/salesNum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:layout_marginTop="52dp"
        android:includeFontPadding="false"
        android:text=""
        android:textColor="@color/_999999"
        android:textSize="@dimen/_11sp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/content"/>

    <TextView
        android:id="@+id/couponTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="78dp"
        android:gravity="center_vertical"
        android:includeFontPadding="false"
        android:text="@string/coupon_text"
        android:textColor="@color/themeColor"
        android:textSize="@dimen/_10sp"
        app:layout_constraintLeft_toLeftOf="@id/content"
        app:layout_constraintTop_toTopOf="@id/content"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="77.5dp"
        android:text="¥"
        android:textColor="@color/themeColor"
        android:textSize="@dimen/_10sp"
        app:layout_constraintLeft_toRightOf="@id/couponTitle"
        app:layout_constraintTop_toTopOf="@id/content"/>

    <TextView
        android:id="@+id/couponPrice"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="72.5dp"
        android:includeFontPadding="false"
        android:text=""
        android:textColor="@color/_fc511f"
        android:textSize="@dimen/_17sp"
        android:textStyle="bold"
        app:layout_constraintLeft_toRightOf="@id/couponTitle"
        app:layout_constraintTop_toTopOf="@id/content"/>

    <TextView
        android:id="@+id/price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:includeFontPadding="false"
        android:text="1"
        android:textColor="@color/_999999"
        android:textSize="@dimen/_11sp"
        app:layout_constraintBottom_toBottomOf="@id/content"
        app:layout_constraintRight_toRightOf="@id/content"/>

    <TextView
        android:id="@+id/money"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="¥"
        android:textColor="@color/_999999"
        android:textSize="@dimen/_11sp"
        app:layout_constraintBottom_toBottomOf="@id/price"
        app:layout_constraintRight_toLeftOf="@id/price"/>

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_gravity="center"
        android:background="@color/_999999"
        app:layout_constraintBottom_toBottomOf="@id/price"
        app:layout_constraintLeft_toLeftOf="@id/money"
        app:layout_constraintRight_toRightOf="@id/price"
        app:layout_constraintTop_toTopOf="@id/price"/>
</android.support.constraint.ConstraintLayout>

 

<layout_item_vertical_normal_second_demo>

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_vertical_goods_all_radius">

    <com.makeramen.roundedimageview.RoundedImageView
        android:id="@+id/goodsImg2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scaleType="fitXY"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:riv_corner_radius_top_left="4dp"
        app:riv_corner_radius_top_right="4dp"/>

    <TextView
        android:id="@+id/specialCount2"
        android:layout_width="50dp"
        android:layout_height="22dp"
        android:background="@drawable/bg_grid_goods_special_count"
        android:ellipsize="end"
        android:gravity="center"
        android:minWidth="50dp"
        android:singleLine="true"
        android:text="@string/special_count"
        android:textColor="@color/white"
        android:textSize="@dimen/_11sp"
        android:visibility="gone"
        app:layout_constraintRight_toRightOf="@id/goodsImg2"
        app:layout_constraintTop_toTopOf="@id/goodsImg2"/>

    <View
        android:id="@+id/content2"
        android:layout_width="match_parent"
        android:layout_height="102dp"
        android:background="@drawable/bg_vertical_normal_goods_bom_radius"
        app:layout_constraintTop_toBottomOf="@id/goodsImg2"/>

    <ImageView
        android:id="@+id/delivery_free2"
        android:layout_width="22dp"
        android:layout_height="12dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="12.5dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@id/content2"/>

    <TextView
        android:id="@+id/goodsTitle2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:ellipsize="end"
        android:gravity="left"
        android:includeFontPadding="false"
        android:maxLines="2"
        android:text=""
        android:textColor="@color/_333333"
        android:textSize="@dimen/_15sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@id/content2"/>

    <TextView
        android:id="@+id/couponValue2"
        android:layout_width="53dp"
        android:layout_height="19dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="50dp"
        android:background="@drawable/bg_coupon_number"
        android:gravity="center"
        android:text="20元券"
        android:textColor="@color/white"
        android:textSize="@dimen/_12sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@id/content2"/>

    <TextView
        android:id="@+id/salesNum2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:layout_marginTop="52dp"
        android:includeFontPadding="false"
        android:text=""
        android:textColor="@color/_999999"
        android:textSize="@dimen/_11sp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/content2"/>

    <TextView
        android:id="@+id/couponTitle2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="78dp"
        android:gravity="center_vertical"
        android:includeFontPadding="false"
        android:text="@string/coupon_text"
        android:textColor="@color/themeColor"
        android:textSize="@dimen/_10sp"
        app:layout_constraintLeft_toLeftOf="@id/content2"
        app:layout_constraintTop_toTopOf="@id/content2"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="77.5dp"
        android:text="¥"
        android:textColor="@color/themeColor"
        android:textSize="@dimen/_10sp"
        app:layout_constraintLeft_toRightOf="@id/couponTitle2"
        app:layout_constraintTop_toTopOf="@id/content2"/>

    <TextView
        android:id="@+id/couponPrice2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="72.5dp"
        android:includeFontPadding="false"
        android:text=""
        android:textColor="@color/_fc511f"
        android:textSize="@dimen/_17sp"
        android:textStyle="bold"
        app:layout_constraintLeft_toRightOf="@id/couponTitle2"
        app:layout_constraintTop_toTopOf="@id/content2"/>

    <TextView
        android:id="@+id/price2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:includeFontPadding="false"
        android:text="1"
        android:textColor="@color/_999999"
        android:textSize="@dimen/_11sp"
        app:layout_constraintBottom_toBottomOf="@id/content2"
        app:layout_constraintRight_toRightOf="@id/content2"/>

    <TextView
        android:id="@+id/money2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="¥"
        android:textColor="@color/_999999"
        android:textSize="@dimen/_11sp"
        app:layout_constraintBottom_toBottomOf="@id/price2"
        app:layout_constraintRight_toLeftOf="@id/price2"/>

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_gravity="center"
        android:background="@color/_999999"
        app:layout_constraintBottom_toBottomOf="@id/price2"
        app:layout_constraintLeft_toLeftOf="@id/money2"
        app:layout_constraintRight_toRightOf="@id/price2"
        app:layout_constraintTop_toTopOf="@id/price2"/>
</android.support.constraint.ConstraintLayout>
加载中
0
r
rooman

布局文件里面有很多 颜色 的字体大小, 可以直接删除

0
B
BigDream

有没有解决方案呢????不止是华为吧,我测试只要是8.0以上的都会出现该问题,数据较多的时候通过

smoothScrollToPosition

回滚到顶部 很明显。

r
rooman
不好意思哦,这个问题一直还没得到解决
0
丶氵

元素过多的item, 滑动出现卡顿,怎么解决

返回顶部
顶部