感謝您的視頻。
這看起來像一個3D旋轉對我來說。動畫可能從適配器的getView
方法開始。這意味着有三個步驟:
- 檢查定製
ListAdapter
,例如, here。您還可以找到這樣
- Click here,看看如何在
getView
- 檢查this answer here啓動動畫了很多問題/答案。它描述了在哪裏可以找到的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);
持續時間i現在很長,但這樣你可以調整值。
對效果的描述將有所幫助。我不知道g +應用程序。 – MalaKa
@MalaKa:我已經做了一個記錄:https://drive.google.com/file/d/0B5uiJlSSk9dZcEIxMWw0X0gtVWs/edit?usp=sharing – wawanopoulos