2014-02-12 2 views
0

사용자가 목록보기에서 스크롤 할 때 목록보기 항목에 효과를 재현하고 싶습니다.Google Plus 앱처럼 목록보기에서 항목 및 항목 이동 애니메이트

Google Plus 애플리케이션과 동일한 효과를 재현하고 싶습니다.

어떻게하면됩니까?

는 UPDATE :

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)); 

UPDATE : 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

감사

다음

내의 getView에서 내 코드의 추출()입니다.
마치 3D 회전과 같습니다. 애니메이션은 아마도 어댑터의 getView 메소드에서 시작됩니다. 즉, 다음 세 단계를 수행해야합니다.

  1. ListAdapter (예 : ListAdapter)을 확인하십시오. here. 또한 getView
  2. 확인 this answer here에 애니메이션을 시작하는 방법을 참조하십시오 그래서
  3. Click here에 대한 질문/답변을 많이 찾을 수 있습니다. 이 곳 3D 애니메이션 나는 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으로 설정되지 않았으므로 매개 변수 centerX과을 제거했습니다. 그리고 이것이 내가 어떻게이

    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); 
    } 
    } 
    

    입니다 : 6,253,455,이 내 업데이트 Rotate3dAnimation됩니다 View view를 추가하고 그것을 애니메이션이 camera.rotateY를 사용하는 rowView

  3. 했다, 그러나 이것은 camera.rotateX

로 변경해야하고 어댑터에서 사용하십시오 :

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

지속 기간 i 지금 꽤 오래지만,이 방법으로 값을 조정할 수 있습니다.

+0

분석 및 링크 해 주셔서 감사합니다. Rotate3dAnimation.java를 찾았습니다. getView() 메소드에도 코드를 추가했는데 loadAnimation 메소드가 애니메이션을위한 XML 파일을 필요로하기 때문에 어떻게 java 파일을 사용할 수 있습니까? (\t \t \t '애니메이션 애니메이션 = AnimationUtils.loadAnimation (는 getContext(), R.anim.slide_top_to_bottom) \t v.startAnimation (애니메이션))' – wawanopoulos

+0

@wawanopoulos 나는 내 대답 – MalaKa

+0

감사를 편집했습니다. 내가 원하는 애니메이션을 재현하기 위해 어떤 매개 변수를 지정할 수 있습니까? – wawanopoulos