ConstraintLayout在RecyclerView中卡顿的问题
1.recyclerview的使用gridlayoutManager布局,每行有四个元素。布局的item使用framelayout作为根布局的时候没有卡顿的现象,在使用ConstraintLayout作为根布局的时候就会卡顿,检测发现cpu消耗比较厉害。
2.
第一种布局:
<FrameLayout
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="match_parent"
android:layout_height="100dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">
<ImageView
android:id="@+id/iv_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp"
android:layout_marginEnd="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:background="#dadada"
android:clickable="false"
android:contentDescription="@string/app_name"
android:focusable="false"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"/>
<View
android:id="@+id/lay_mask"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginEnd="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:background="@color/black_alpha_80"
android:clickable="false"
android:focusable="false"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/iv_image"
app:layout_constraintDimensionRatio="h,1:1"
app:layout_constraintLeft_toLeftOf="@+id/iv_image"
app:layout_constraintRight_toRightOf="@+id/iv_image"
app:layout_constraintTop_toTopOf="@+id/iv_image"/>
<ImageView
android:id="@+id/cb_selected"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="top|right"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:clickable="false"
android:contentDescription="@string/app_name"
android:focusable="false"
android:scaleType="centerInside"
android:src="@drawable/cb_select_image_check_selector"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded"/>
</FrameLayout>
第二种布局
<android.support.constraint.ConstraintLayout
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="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#dadada"
android:clickable="false"
android:contentDescription="@string/app_name"
android:focusable="false"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1"/>
<View
android:id="@+id/lay_mask"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/black_alpha_80"
android:clickable="false"
android:focusable="false"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/iv_image"
app:layout_constraintDimensionRatio="h,1:1"
app:layout_constraintLeft_toLeftOf="@+id/iv_image"
app:layout_constraintRight_toRightOf="@+id/iv_image"
app:layout_constraintTop_toTopOf="@+id/iv_image"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"/>
<ImageView
android:id="@+id/cb_selected"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="top|right"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:clickable="false"
android:contentDescription="@string/app_name"
android:focusable="false"
android:scaleType="centerInside"
android:src="@drawable/cb_select_image_check_selector"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded"
android:layout_marginEnd="8dp"/>
</android.support.constraint.ConstraintLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同样是替换item rootlayout为constraintlayout,我发现它并不能填充item。。。?
你的在布局上很正常吗?