当用户在列表视图中滚动时,我想重现列表视图项的效果。
我想重现与Google Plus应用程序相同的效果。
我该怎么做?
更新:
以下是我的getView()代码的摘录:
final float centerX = rowView.getWidth() / 2.0f;
final float centerY = rowView.getHeight() / 2.0f;
rowView.startAnimation(new Rotate3dAnimation(0.0f, -90.0f, centerX, centerY, 310.0f, true));
更新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)
答案 0 :(得分:1)
感谢视频。
对我来说,这看起来像3D旋转。动画可能是在适配器的getView
方法中启动的。这意味着有三个步骤:
ListAdapter
,例如here。你也会发现很多问题/答案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
并添加了View view
并将其赋予rowView
} camera.rotateY
,但需要将其更改为camera.rotateX
这是我更新的Rotate3dAnimation:
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);
现在持续时间很长,但这样你可以调整值。