的第一要素。畫廊的每個項目都採用整個屏幕的寬度。我還放置了一個按鈕來翻轉。如果我點擊了翻頁按鈕,當第一項顯示在畫廊中時,它不會顯示翻頁的動畫。但是,如果我滾動畫廊並轉到其他項目或再次返回到第一個項目,則動畫可以正常工作。任何人都可以猜測問題出在哪裏。動畫不工作,因爲我已經使用了一個畫廊Android圖庫
我打電話與所選項目的位置的方法flipView。對於動畫的方法和類給出如下:
public void flipView(int position) {
applyRotation(0, 90, position);
isFrontShowing[position] = !isFrontShowing[position];
}
private void applyRotation(float start, float end, int position) {
// Find the center of image
final float centerX, centerY;
if(isFrontShowing[position] == true) {
centerX = detailsLayout[position].getMeasuredWidth()/2.0f;
centerY = detailsLayout[position].getMeasuredHeight()/2.0f;
detailsLayout[position].requestFocus();
detailsLayout[position].bringToFront();
} else {
centerX = scriptLayout[position].getMeasuredWidth()/2.0f;
centerY = scriptLayout[position].getMeasuredHeight()/2.0f;
scriptLayout[position].requestFocus();
scriptLayout[position].bringToFront();
}
final Rotate3dAnimation rotation =
new Rotate3dAnimation(start, end, centerX, centerY, 200.0f, true);
rotation.setDuration(350);
rotation.setFillAfter(true);
rotation.setInterpolator(new LinearInterpolator());
rotation.setAnimationListener(new DisplayNextView(isFrontShowing[position], detailsLayout[position], scriptLayout[position]));
if (isFrontShowing[position] == true)
{
detailsLayout[position].startAnimation(rotation);
} else {
//System.out.println("---Backward flipping started...");
scriptLayout[position].startAnimation(rotation);
}
}
import android.view.animation.Animation;
進口android.view.animation.Transformation; import android.graphics.Camera; import android.graphics.Matrix;
公共類Rotate3dAnimation擴展動畫{ 私人最終浮動mFromDegrees; private final float mToDegrees; private final float mCenterX; private final float mCenterY; private final float mDepthZ; private final boolean mReverse; 私人相機mCamera; 公共Rotate3dAnimation(浮動fromDegrees,浮toDegrees, 浮子的centerX,浮centerY,浮depthZ,布爾反向){ mFromDegrees = fromDegrees; mToDegrees = toDegrees; mCenterX = centerX; mCenterX = centerX; mCenterY = centerY; mDepthZ = depthZ; mReverse =反向; }
@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 = mCenterX;
final float centerY = mCenterY;
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.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
package com.vocabAhead.SATVocab;
進口android.view.animation.Animation; import android.widget.RelativeLayout;
公共final類DisplayNextView實現Animation.AnimationListener { 私人布爾mCurrentView; RelativeLayout layout1; RelativeLayout layout2;
public DisplayNextView(boolean currentView, RelativeLayout layout1,
RelativeLayout layout2) {
mCurrentView = currentView;
this.layout1 = layout1;
this.layout2 = layout2;
}
public void onAnimationStart(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
if(mCurrentView == true)
layout1.post(new SwapViews(mCurrentView, layout1, layout2));
else
layout2.post(new SwapViews(mCurrentView, layout1, layout2));
}
public void onAnimationRepeat(Animation animation) {
}
}
package com.vocabAhead.SATVocab;
進口android.view.View; import android.view.animation.Animation; 進口android.view.animation.LinearInterpolator; 進口android.view.animation.Animation.AnimationListener; import android.widget.RelativeLayout;
公共final類SwapViews實現Runnable { 私人布爾mIsFirstView; RelativeLayout layout1; RelativeLayout layout2;
public SwapViews(boolean isFirstView, RelativeLayout layout1, RelativeLayout layout2) {
mIsFirstView = isFirstView;
this.layout1 = layout1;
this.layout2 = layout2;
}
public void run() {
final float centerX, centerY;
if(mIsFirstView) {
centerX = layout1.getWidth()/2.0f;
centerY = layout1.getHeight()/2.0f;
} else {
centerX = layout2.getWidth()/2.0f;
centerY = layout2.getHeight()/2.0f;
}
Rotate3dAnimation rotation;
if (mIsFirstView == true) {
layout1.setVisibility(View.GONE);
layout2.setVisibility(View.VISIBLE);
layout2.requestFocus();
layout2.bringToFront();
rotation = new Rotate3dAnimation(-90, 0, centerX, centerY, 200.0f, false);
} else {
layout2.setVisibility(View.GONE);
layout1.setVisibility(View.VISIBLE);
layout1.requestFocus();
layout1.bringToFront();
rotation = new Rotate3dAnimation(-90, 0, centerX, centerY, 200.0f, false);
//rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
}
rotation.setDuration(350);
rotation.setFillAfter(true);
rotation.setInterpolator(new LinearInterpolator());
rotation.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation arg0) {
}
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation arg0) {
WordDetailItemAdapter.notifyAdapter();
}
});
if (mIsFirstView == true) {
layout2.startAnimation(rotation);
} else {
layout1.startAnimation(rotation);
}
}
}