Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在listview中设置添加项目和项目移动的动画,如Google Plus应用程序_Android_Listview_Android Listview - Fatal编程技术网

Android 在listview中设置添加项目和项目移动的动画,如Google Plus应用程序

Android 在listview中设置添加项目和项目移动的动画,如Google Plus应用程序,android,listview,android-listview,Android,Listview,Android Listview,我希望在用户在listview中滚动时,在listview项目上重现该效果 我想复制与Google Plus应用程序相同的效果 我该怎么做 更新: 下面是我在getView()中的代码摘录: 更新2: 02-12 16:01:17.198: E/AndroidRuntime(21625): java.lang.NullPointerException 02-12 16:01:17.198: E/AndroidRuntime(21625): at com.rss.home.ArticleLi

我希望在用户在listview中滚动时,在listview项目上重现该效果

我想复制与Google Plus应用程序相同的效果

我该怎么做

更新:

下面是我在getView()中的代码摘录:

更新2:

02-12 16:01:17.198: E/AndroidRuntime(21625): java.lang.NullPointerException
02-12 16:01:17.198: E/AndroidRuntime(21625):    at com.rss.home.ArticleListAdapterHome.getView(ArticleListAdapterHome.java:129)
02-12 16:01:17.198: E/AndroidRuntime(21625):    at android.widget.AbsListView.obtainView(AbsListView.java:2263)
02-12 16:01:17.198: E/AndroidRuntime(21625):    at android.widget.ListView.makeAndAddView(ListView.java:1790)
02-12 16:01:17.198: E/AndroidRuntime(21625):    at android.widget.ListView.fillDown(ListView.java:691)
02-12 16:01:17.198: E/AndroidRuntime(21625):    at android.widget.ListView.fillFromTop(ListView.java:752)
谢谢你的视频。
这看起来像是一个3D旋转。动画可能是在适配器的
getView
方法中启动的。这意味着需要执行三个步骤:

  • 检查自定义
    列表适配器
    ,例如。你还会发现很多问题/答案
  • 查看如何在
    getView
  • 检查。它描述了在哪里可以找到三维动画的示例
  • 我自己还没有检查3D动画,但是上面的
    ListAdapter
    Animation
    应该不是什么大问题


    编辑
    您不必从xml加载动画。你可以这样做:

    public View getView(int position, View view, ViewGroup viewGroup) {
        // normal handling
        // ...
        // now apply animation
        view.startAnimation(new Rotate3dAnimation(/*params*/));
    }
    

    Edit2
    现在,我已经亲自测试了它,以下是我为使其工作所做的更改:

  • 我忘了设置动画的持续时间,是我设置的
  • 视图的高度和宽度未在
    getView
    中设置,因此删除了参数
    centerX
    centerY
    ,并添加了
    视图视图
    ,并将其命名为
    行视图
  • 动画使用的是
    camera.rotateY
    ,但这需要更改为
    camera.rotateX
  • 这是我的最新信息:

    package de.malaka.player.animation;
    
    import android.view.View;
    import android.view.animation.Animation;
    import android.view.animation.Transformation;
    import android.graphics.Camera;
    import android.graphics.Matrix;
    
    /**
     * An animation that rotates the view on the Y axis between two specified angles.
     * This animation also adds a translation on the Z axis (depth) to improve the effect.
     */
    public class Rotate3dAnimation extends Animation {
    private final float mFromDegrees;
    private final float mToDegrees;
    private final float mDepthZ;
    private final View mView;
    private final boolean mReverse;
    private Camera mCamera;
    
    /**
     * Creates a new 3D rotation on the Y axis. The rotation is defined by its
     * start angle and its end angle. Both angles are in degrees. The rotation
     * is performed around a center point on the 2D space, definied by a pair
     * of X and Y coordinates, called centerX and centerY. When the animation
     * starts, a translation on the Z axis (depth) is performed. The length
     * of the translation can be specified, as well as whether the translation
     * should be reversed in time.
     *
     * @param fromDegrees the start angle of the 3D rotation
     * @param toDegrees the end angle of the 3D rotation
     * @param centerX the X center of the 3D rotation
     * @param centerY the Y center of the 3D rotation
     * @param reverse true if the translation should be reversed, false otherwise
     */
    public Rotate3dAnimation(float fromDegrees, float toDegrees, float depthZ, boolean reverse, View view) {
        mFromDegrees = fromDegrees;
        mToDegrees = toDegrees;
        mDepthZ = depthZ;
        mReverse = reverse;
        mView = view;
    }
    
    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        mCamera = new Camera();
    }
    
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        final float fromDegrees = mFromDegrees;
        float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
    
        final float centerX = mView.getWidth()/2;
        final float centerY = mView.getHeight()/2;
        final Camera camera = mCamera;
    
        final Matrix matrix = t.getMatrix();
    
        camera.save();
        if (mReverse) {
            camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
        } else {
            camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
        }
        camera.rotateX(degrees);
        camera.getMatrix(matrix);
        camera.restore();
    
        matrix.preTranslate(-centerX, -centerY);
        matrix.postTranslate(centerX, centerY);
    }
    }
    
    以下是我在适配器中使用它的方式:

    Animation anim = new Rotate3dAnimation(90.0f, 0.0f, 100.0f, false, convertView);
    anim.setDuration(1000l);
    convertView.startAnimation(anim);
    

    目前持续时间相当长,但通过这种方式可以调整值。

    对效果的描述会有所帮助。我不知道g+应用程序。@MalaKa:我已经做了效果记录:谢谢你的分析和链接。我已经找到了Rotate3dAnimation.java,我还在getView()方法中添加了代码,但是如何使用java文件,因为loadAnimation方法需要xml文件来制作动画?('Animation Animation=AnimationUtils.loadAnimation(getContext(),R.anim.slide\u top\u to\u bottom);v.startAnimation(Animation);)谢谢。你知道我可以指定哪个参数来复制我想要的动画吗?我猜
    视图的中心是你的
    centerX
    centerY
    ,而
    toDegrees
    将是0,
    fromdgrees
    可能是45(或者-45,你需要测试它)你还得玩一下
    depthZ
    ,我不知道
    depthZ
    的效果到底会是什么样子。@wawanopoulos我现在开始工作了,请检查我答案的第二次更新。我得到了一个异常(nullPointerException)。请查阅我的最新资料2。
    Animation anim = new Rotate3dAnimation(90.0f, 0.0f, 100.0f, false, convertView);
    anim.setDuration(1000l);
    convertView.startAnimation(anim);