用户触摸回收站视图项目时缩放动画

时间:2019-09-06 22:24:43

标签: android android-recyclerview android-animation android-cardview

我正在开发一个应用程序,其中有一张带有一些卡片的recyclerview,并希望在用户触摸卡时创建放大效果,并在释放触摸时创建缩小效果。上一张和下一张卡片在扩展时应注意其尺寸,而不是在后面或在后面

我想创建类似于this layout manager的东西,但是要触摸屏幕而不是滚动。

   //RecyclerView
    recyclerView = view.findViewById(R.id.recyclerView)

    recyclerView.setHasFixedSize(false)

    recyclerView.layoutManager = CenterZoomLayoutManager(activity, LinearLayoutManager.VERTICAL, false)

如何创建这种效果? 预先感谢。

2 个答案:

答案 0 :(得分:4)

您可以使用$array = json_decode($json); foreach ($array as $innerArray){ foreach ($innerArray as $key=>$value){ if($key == 'field_gita_10409_text'){ $exp = explode($value); } } } 实现类似的目标。在此示例中,我将stateListAnimator附加到了recyclerView项目。当项目被按下时比例为1,当未按下时比例为0.8

result

recyclerview_item.xml

stateListAnimator

res / animator / list_animator.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"/>

答案 1 :(得分:0)

请在 onBindViewHolder 中使用以下代码来实现项目缩放

    itemView.setOnTouchListener { view, motionEvent ->
    when (motionEvent.action) {
         MotionEvent.ACTION_DOWN -> {                  
           view.animate().scaleX(1.10f).scaleY(1.10f).setDuration(100).start()
           (itemView.parent as RecyclerView).addOnItemTouchListener(object : 
           RecyclerView.OnItemTouchListener {
             override fun onInterceptTouchEvent(rv: RecyclerView, 
             e: MotionEvent): Boolean {
                   if (rv.scrollState == RecyclerView.SCROLL_STATE_DRAGGING) {
             view.animate().scaleX(1.0f).scaleY(1.0f).setDuration(100).start() 
             }
             return false               }
             override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
             override fun 
             onRequestDisallowInterceptTouchEvent(disallowIntercept: 
                          Boolean) { }})
             }
         MotionEvent.ACTION_UP -> {                     
               view.animate().scaleX(1.0f).scaleY(1.0f).setDuration(100).start()
             }
         }
         true
      }