【发布时间】:2021-03-26 13:06:17
【问题描述】:
我在RecyclerView 上方有一个ImageView,当我滚动浏览RecyclerView 时,我试图找到一种方法来更新ImageView,其中RecyclerView 的顶部项目(图像)被放大并显示在滚动时的 ImageView。
经过一番挖掘,我发现我可以使用ItemTouchHelper.SimpleCallback 或ItemTouchHelper.Callback。但是,两者都实现了我不想在我自己的 RecyclerView 中使用的滑动动画,或者我根本没有找到摆脱这些动画的方法。
我希望我的解释足够清楚,如果没有评论将不胜感激。
这是我的 xml 文件供参考:
<layout 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">
<data>
<variable
name="viewModel"
type="com.example.collection.presentation.overview.CollectionOverviewViewModel" />
<variable
name="plantPhoto"
type="com.example.storage.data.PlantPhoto" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<Button
android:id="@+id/to_collection_overview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/collection_overview"
app:layout_constraintBottom_toTopOf="@+id/collection_individual_imageview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.882"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.17000002" />
<ImageView
android:id="@+id/collection_individual_imageview"
android:layout_width="150dp"
android:layout_height="200dp"
android:adjustViewBounds="false"
app:singleImage="@{viewModel.plantPhotoDisplay.plantFilePath}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26999998"
tools:srcCompat="@tools:sample/avatars" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/collection_individual_recyclerview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/collection_individual_imageview"
app:layout_constraintVertical_bias="0.498"
app:listPhotoData="@{viewModel.listPlantPhoto}"
tools:listitem="@layout/image_plant_photo_view" />
<TextView
android:id="@+id/test_individual"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="Name"
app:layout_constraintBottom_toTopOf="@+id/collection_individual_recyclerview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/collection_individual_imageview" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
【问题讨论】:
标签: android kotlin android-recyclerview imageview