Vit*_*ira 3 android android-animation android-cardview android-recyclerview
我正在开发一个应用程序,其中有一个带有一些卡片的 recyclerview,并希望在用户触摸卡片时创建放大效果,并在释放触摸时缩小效果。上一张和下一张卡片在扩展时应该尊重卡片的大小,而不是后面或前面
我想创建类似于这个布局管理器的东西,但是通过触摸屏幕而不是滚动。
//RecyclerView
recyclerView = view.findViewById(R.id.recyclerView)
recyclerView.setHasFixedSize(false)
recyclerView.layoutManager = CenterZoomLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
Run Code Online (Sandbox Code Playgroud)
这种效果如何制作?提前致谢。
您可以使用stateListAnimator. 在这个例子中,我附加stateListAnimator到了 recyclerView 项目。当项目被按下时,比例为 1,当项目未按下时,比例为 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"/>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)