與Theme.Dialog
應用,如果你正在創建的對話作爲一項活動,那麼你可以按照這個方法
您可以創建動畫類的activity
:
public class DropDownToMiddleAnimation extends Animation {
public int height, width;
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
// TODO Auto-generated method stub
super.initialize(width, height, parentWidth, parentHeight);
this.width = width;
this.height = height;
setDuration(500);
setFillAfter(true);
setInterpolator(new LinearInterpolator());
}
Camera camera = new Camera();
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
// TODO Auto-generated method stub
super.applyTransformation(interpolatedTime, t);
Matrix matrix = t.getMatrix();
camera.save();
camera.getMatrix(matrix);
matrix.setTranslate(0, ((height/2) * interpolatedTime)));
matrix.preTranslate(0, -height);
camera.restore();
this.setAnimationListener(this);
}
和:
public class MiddleToTopAnimation extends Animation {
public int height, width;
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
// TODO Auto-generated method stub
super.initialize(width, height, parentWidth, parentHeight);
this.width = width;
this.height = height;
setDuration(500);
setFillAfter(true);
setInterpolator(new LinearInterpolator());
}
Camera camera = new Camera();
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
// TODO Auto-generated method stub
super.applyTransformation(interpolatedTime, t);
Matrix matrix = t.getMatrix();
camera.save();
camera.getMatrix(matrix);
matrix.setTranslate(0, -((height/2) * interpolatedTime)));//here is the change
matrix.preTranslate(0, -height);
camera.restore();
this.setAnimationListener(this);
}
,並與你的對話
使用它們3210
LinearLayout ll = (LinearLayout) findViewById(R.id.parentLayout);//parent layout in the xml, which serves as the background in the custom dialog
ll.startAnimation(new DropDownToMiddleAnimation());//use with launching of the dialog
ll.startAnimation(new MiddleToTopAnimation());//use while dismissing the dialog/finishing the dialog activity
你是如何將這些動畫? – Joru 2012-07-10 13:09:26
我想如果你打開「對話活動」,那麼這個過渡很容易實現。 – 2012-07-10 13:09:44
你在用什麼? DialogFragment?將代碼粘貼到您應用轉換的地方並提交交易。 – 2012-07-10 13:11:41