列表视图,当滚动像Carousel视图android时,行的更改宽度

时间:2013-12-06 06:53:55

标签: android listview animation carousel

我正在尝试实现动画列表视图。如下图所示,当列表视图项完全可见时,完全可见项的时间改变宽度,其他方面宽度保持默认宽度为给定。蓝色项目宽度小时不完全可见但是当绿色项目进入屏幕中间时,它的宽度将进入带动画的完整模式。如何在列表视图中实现这种类型的动画?

用列表项的动画改变即将到来的项目的大小。

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码...并进行更改以适应您。

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.ListView;

public class MyListView extends ListView {
    private final Transformation mTransformation;

    public MyListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        if (!isInEditMode()) {
            setStaticTransformationsEnabled(true);
            mTransformation = new Transformation();
            mTransformation.setTransformationType(Transformation.TYPE_MATRIX);
        } else {
            mTransformation = null;
        }      
    }

    @Override
    protected boolean getChildStaticTransformation(View child, Transformation t) {
        mTransformation.getMatrix().reset();
        final int childTop = Math.max(0,child.getTop());
        final int parentHeight = getHeight();
//      Log.d("details1","childTop : "+childTop+" , parentHeight : "+parentHeight );
        final float scale = (float)(parentHeight-(childTop/2))/getHeight();
//      Log.d("details2", "parentHeight-(childTop/2) : "+ (parentHeight-(childTop/2)) );
//      Log.d("details3", "getHeight() : "+getHeight());
//      Log.d("scale",scale+"");
        final float px = child.getLeft() + (child.getWidth()) / 2;
        final float py = (child.getTop() + (child.getHeight()) / 2);
//      Log.d("details4", "child.getLeft() : "+child.getLeft()+ ",  child.getWidth(): "+child.getWidth()+" , child.getTop(): "+child.getTop()+" , child.getHeight()"+child.getHeight());
//      Log.d("px py", px +" , "+py);
//      Log.e("end", "end");
        mTransformation.getMatrix().preScale(scale, scale);

        t.compose(mTransformation);
        return true;
    }

}