gpt4 book ai didi

android - 对话过渡效果

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:48:36 24 4
gpt4 key购买 nike

我目前正在为我的对话框制作过渡效果。请引用下图:enter image description here

我的对话框的进入动画应该从上到中。而退出动画应该在中间到顶部。我正在使用以下 XML 动画,但不幸的是,它们不起作用。

slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%p" android:toYDelta="0"
android:duration="1000"/>
</set>

slide_up.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0%p" android:toYDelta="50%p"
android:duration="1000"/>

编辑:这不是一个普通的Dialog。它是一个 activity,在 AndroidManifest.xml

中应用了一个 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);
}

并将它们与您的对话一起使用

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

关于android - 对话过渡效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11413817/

24 4 0
文章推荐: javascript - 在 Math.pow 运算中获取 NaN,第二个参数为十进制值
文章推荐: javascript - javascript后台url中的括号
文章推荐: javascript - list.js 的下拉列表