2014-02-12 22 views
0

我想重現列表視圖項目,當用戶在列表視圖中滾動時出現的效果。動畫在列表視圖中添加項目和項目移動像谷歌加應用程序

我想重現與Google Plus應用程序相同的效果。

我該怎麼做?

UPDATE:

這裏是我的代碼在我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

對效果的描述將有所幫助。我不知道g +應用程序。 – MalaKa

+0

@MalaKa:我已經做了一個記錄:https://drive.google.com/file/d/0B5uiJlSSk9dZcEIxMWw0X0gtVWs/edit?usp=sharing – wawanopoulos

回答

1

感謝您的視頻。
這看起來像一個3D旋轉對我來說。動畫可能從適配器的getView方法開始。這意味着有三個步驟:

  1. 檢查定製ListAdapter,例如, here。您還可以找到這樣
  2. Click here,看看如何在getView
  3. 檢查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
現在我已經測試它自己,這裏的東西我改變,使其工作:

  1. 我忘了把動畫的持續時間,我確實設置了這個
  2. 視圖的高度和寬度沒有在getView中設置,所以刪除了參數centerXcenterY並添加View view並賦予它rowView
  3. 動畫使用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現在很長,但這樣你可以調整值。

+0

感謝您的分析和鏈接。我找到了Rotate3dAnimation.java,我也在我的getView()方法中添加了代碼,但是如何使用java文件,因爲loadAnimation方法需要動畫的xml文件? (\t \t \t '動畫動畫= AnimationUtils.loadAnimation(的getContext(),R.anim.slide_top_to_bottom); \t v.startAnimation(動畫);)' – wawanopoulos

+0

@wawanopoulos我已經編輯我的答案 – MalaKa

+0

感謝。你有沒有想過我可以指定哪些參數來重現我想要的動畫? – wawanopoulos

相關問題