我正在开发一个应用程序,其中有一个带有一些卡片的 recyclerview,我想在用户触摸卡片时创建放大效果,并在释放触摸时创建缩小效果。前一张和下一张卡片在扩展时应遵循卡片的大小,而不是向前或向后
我想创建类似于 this layout manager 的东西,而是通过触摸屏幕而不是滚动。
//RecyclerView
recyclerView = view.findViewById(R.id.recyclerView)
recyclerView.setHasFixedSize(false)
recyclerView.layoutManager = CenterZoomLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
如何创建这种效果? 提前致谢。
最佳答案
您可以使用 stateListAnimator
实现类似的功能。在此示例中,我将 stateListAnimator
附加到 recyclerView 项目。 item被按下时scale为1,未按下时scale为0.8
recyclerview_item.xml
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/item_animal_height"
android:background="#f00"
android:stateListAnimator="@animator/list_animator"/>
res/animator/list_animator.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<set>
<objectAnimator android:propertyName="scaleX"
android:valueTo="1"/>
<objectAnimator android:propertyName="scaleY"
android:valueTo="1"/>
</set>
</item>
<item
android:state_pressed="false">
<set>
<objectAnimator android:propertyName="scaleX"
android:valueTo="0.8"/>
<objectAnimator android:propertyName="scaleY"
android:valueTo="0.8"/>
</set>
</item>
</selector>
关于android - 当用户触摸 recyclerview 项目时缩放动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57829139/