我正在使用约束布局的alpha4 implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha4'
。首先,我创建了一个布局,并对其进行onswipe动画处理,使其与运动布局完美配合,然后使用recyclerview对布局进行了修补。 现在问题浮出水面了
问题:
我已将整个项目发布到Github,还创建了一个示例video。
_在此处获得运动布局的快速要领
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout
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"
app:layoutDescription="@xml/scene_btn"
app:showPaths="true"
>
<androidx.cardview.widget.CardView
android:id="@+id/iv_recorded_program"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:cardElevation="1dp"
app:cardCornerRadius="0dp"
app:layout_constraintEnd_toStartOf="@+id/rl_recorded_program_info"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
style="@style/styleRecordedProgramImage"
android:layout_width="@dimen/guide_list_width"
android:layout_height="@dimen/guide_list_height"
android:visibility="visible"
/>
</androidx.cardview.widget.CardView>
<include
android:id="@+id/rl_recorded_program_info"
layout="@layout/text"
android:layout_width="0dp"
android:layout_height="@dimen/guide_list_height"
android:background="@color/colorPrimary"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="@+id/button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/iv_recorded_program"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="@dimen/guide_list_height"
android:background="@color/colorAccent"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.motion.widget.MotionLayout>
这是布局说明
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<Transition
app:constraintSetEnd="@+id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe
app:dragDirection="dragRight"
app:touchAnchorId="@id/rl_recorded_program_info"
app:touchAnchorSide="right"/>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/iv_recorded_program"
android:layout_width="@dimen/guide_list_width"
android:layout_height="@dimen/guide_list_height"
android:elevation="10dp"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="@+id/rl_recorded_program_info"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Constraint
android:id="@id/rl_recorded_program_info"
android:layout_width="0dp"
android:layout_height="@dimen/guide_list_height"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="@+id/button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/iv_recorded_program"
app:layout_constraintTop_toTopOf="parent"/>
<Constraint
android:id="@id/button"
android:layout_width="0dp"
android:layout_height="@dimen/guide_list_height"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/iv_recorded_program"
android:layout_width="@dimen/guide_list_width"
android:layout_height="@dimen/guide_list_height"
android:elevation="10dp"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Constraint
android:id="@id/rl_recorded_program_info"
android:layout_width="0dp"
android:layout_height="@dimen/guide_list_height"
app:layout_constraintEnd_toStartOf="@+id/button"
app:layout_constraintStart_toStartOf="@+id/iv_recorded_program"
app:layout_constraintTop_toTopOf="parent"/>
<Constraint
android:id="@id/button"
android:layout_width="0dp"
android:layout_height="@dimen/guide_list_height"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/iv_recorded_program"
app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>
</MotionScene>
答案 0 :(得分:0)
最后,问题由一位同事解决。 @Srini感谢您的解决方案。
@Override
public int getItemViewType(int position) {
return position;
}
只需在recyclerview的适配器中重写此方法。
[注意:]在滑动时仍然有滞后。