小编Mos*_*ail的帖子

为什么在 RecyclerView 项中 ConstraintLayout 比 LinearLayout 慢?

我正在将 recyclyerView 的 xml 项从 LinearLayout 更改为 ConstraintLayout。当我水平滚动 recyclerView 时,它比 LinearLayout 滞后并且呈现得非常慢。

约束布局

约束布局

线性布局

线性布局

在这里,我将分享我的 ConstraintLayout xml。

我的 ConstraintLayout 项目

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="85dp"
    android:layout_height="wrap_content">

<android.support.constraint.ConstraintLayout
    android:id="@+id/merchant_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginEnd="5dp"
    android:layout_marginStart="5dp">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/merchant_img"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:transitionName="profile"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="UnusedAttribute"
        tools:src="@drawable/avatar" />

    <com.max.xclusivekotlin.customViews.MyTextView
        android:id="@+id/merchant_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="5dp"
        android:layout_marginStart="5dp"
        android:layout_marginTop="5dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:maxWidth="72dp"
        android:minWidth="72dp"
        android:textAlignment="center"
        android:textColor="@color/blackFont"
        android:textSize="14sp"
        app:layout_constraintEnd_toEndOf="@id/merchant_img"
        app:layout_constraintStart_toStartOf="@id/merchant_img"
        app:layout_constraintTop_toBottomOf="@id/merchant_img"
        tools:text="Chili's" />

    <com.max.xclusivekotlin.customViews.MyTextView
        android:id="@+id/merchant_offer_percent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/redColor"
        android:textSize="12sp"
        app:layout_constraintBottom_toTopOf="@id/tv_distance"
        app:layout_constraintEnd_toStartOf="@id/merchant_offer_type"
        app:layout_constraintStart_toStartOf="@id/merchant_name"
        app:layout_constraintTop_toBottomOf="@id/merchant_name"
        app:textBold="bold"
        tools:text="25%" />

    <com.max.xclusivekotlin.customViews.MyTextView
        android:id="@+id/merchant_offer_type"
        android:layout_width="0dp"
        android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-recyclerview android-constraintlayout

6
推荐指数
2
解决办法
3717
查看次数