确定ScaleAnimation枢轴

时间:2017-12-13 14:49:13

标签: java android animation kotlin scale

我有一个视图,我正在缩放列表,模拟列表项垂直缩放到全屏。

以下示例github project 一起使用动画代码为here

enter image description here

代码如下所示:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/growView"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/fiftyBlack" />
</FrameLayout>

view.setOnClickListener {

    val listItemHeight = it.measuredHeight
    val toolBarHeight = (it.parent as RecyclerView).y
    val scalingView = it.rootView.findViewById<View>(R.id.growView)
    val screenHeight = (scalingView.parent as FrameLayout).measuredHeight

    // Position the view exactly over the list item
    scalingView.y = it.y + toolBarHeight
    scalingView.layoutParams.height = listItemHeight
    scalingView.layoutParams = scalingView.layoutParams

    /* 
      pivots[0] scales example animation for the first item of the list 
      for xxhdpi: 1080p device
      for the rest of the visible items the pivots are: 1.954f, 3.131f .... +1.177 (no scroll)
    */ 
    val pivots = arrayListOf(0.777f)
    val itemScale = screenHeight.toFloat()/listItemHeight


    val scaleAnime = ScaleAnimation(1f, 1f, 1f, itemScale,
            Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, pivots[0])
    scaleAnime.setDuration(400);
    scaleAnime.setFillAfter(true);
    scalingView.startAnimation(scaleAnime);

您可能会发现问题在于确定每个项目的y轴点:

val scaleAnime = ScaleAnimation( /.....* Dynamic vertical pivot */)

我正在努力确定枢轴点几天,但无法弄清楚它取决于什么。

任何想法可能是什么?

0 个答案:

没有答案