在android中更改活动时向上滑动xml动画

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11912277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:09:13  来源:igfitidea点击:

slide up xml animation on change activity in android

androidandroid-layoutandroid-activityandroid-animationslideup

提问by praveen kumar

I read the below link before posting this.

在发布之前,我阅读了以下链接。

How to apply slide animation between two activities in Android?

如何在 Android 中的两个活动之间应用幻灯片动画?

I need to know how to make activity slideup xml animation. like what they have done for fadein and fadeout.

我需要知道如何制作活动幻灯片 xml 动画。就像他们为淡入淡出所做的那样。

回答by georgiecasey

The accepted answer isn't what the question was asking, which is animations that slide up from the bottom and slide out from the top.

接受的答案不是问题所问的问题,即从底部向上滑动并从顶部滑出的动画。

pull_up_from_bottom.xml:

pull_up_from_bottom.xml

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

push_out_to_bottom.xml:

push_out_to_bottom.xml

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

回答by Mansi

for slide_in xml :

对于 slide_in xml :

<translate 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:duration="250" 
      android:fromXDelta="-100%p" 
      android:toXDelta="0%p">
</translate>

for slide_out xml:

对于 slide_out xml:

<translate
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:duration="200" 
      android:fromXDelta="0" 
      android:toXDelta="100%p">
</translate>

Java code :

Java代码:

Intent intent = new Intent(this, newActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);

put both xml files in res/anim folder.

将两个 xml 文件放在 res/anim 文件夹中。

回答by Tiago

This is what I was after:

这就是我所追求的:

res/anim/slide_up.xml

res/anim/slide_up.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="100%"
android:toYDelta="0%" />

res/anim/slide_down.xml

res/anim/slide_down.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="0%" />

res/anim/slide_down_reverse.xml

res/anim/slide_down_reverse.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="0%" />

res/anim/slide_up_reverse.xml

res/anim/slide_up_reverse.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromYDelta="0%"
android:toYDelta="100%" />

YourActivity.kt

你的活动.kt

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setContentView(R.layout.your_layout)

    overridePendingTransition(R.anim.slide_up, R.anim.slide_down)
}

override fun finish() {
    super.finish()

    overridePendingTransition(R.anim.slide_down_reverse, R.anim.slide_up_reverse)
}

回答by Mehul Boghra

You can use below code for slide up activity transition animation.

您可以使用以下代码进行向上滑动活动过渡动画。

startActivity(new Intent(MainActivity.this, DataSetActivity.class));
overridePendingTransition(R.anim.slide_out_bottom, R.anim.slide_in_bottom);

R.anim.slide_out_bottom

R.anim.slide_out_bottom

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="250"
        android:fromXDelta="0%"
        android:fromYDelta="100%"
        android:toXDelta="0%"
        android:toYDelta="0%" />
</set>

R.anim.slide_in_bottom

R.anim.slide_in_bottom

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="200"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="100%" />
</set>