指定的翻译持续时间(在动画资源文件中)在第二个开始时不起作用 Activity
specified duration for translate (in anim resource file) not working while starting second Activity
首先我使用的是API 28 (Android 9.0)
当我单击 mainActivity 上的菜单按钮时,我希望我的第二个 activity 从左到右出现。
我已经覆盖了 main activity 中的挂起转换,如下所示:
startActivity(myintent);
this.overridePendingTransition(R.anim.left_to_right, R.anim.no_move);
持续时间为 100 毫秒的 left_to_right.xml(这似乎不是 100 毫秒,差不多 1 秒,但动画效果很好):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="100"
android:fromYDelta="0%"
android:fromXDelta="-100%"
android:toXDelta="0%"
android:toYDelta="0%">
</translate>
</set>
和no_move.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%"
android:toYDelta="0%"
android:fromXDelta="0%"
android:toXDelta="0%">
</translate>
</set>
这是我的 theme.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Chess" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="android:windowActivityTransitions">true</item>
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
activity 以我想要的方式开始(动画),但唯一的问题是它的 duration.it 需要 1 秒才能完成翻译。
这里没有额外的代码要提及,我添加的只是 2 个动画文件和覆盖 pendingTranstition
加上在 themes.xml
中将 windowActivityTransition 设置为 True
我想做什么...
我想要的动画就像你在 Telegram 应用程序中单击菜单按钮(在顶部和左侧)时,菜单会顺利显示,我想要这样漂亮的东西。
所以如果有更好的方法来做这些事情,或者如果电报使用另一种方式来制作这个漂亮的动画,请告诉我。
提前致谢。
使用一个 activity
和 DrawerLayout view
for that left menu. It has open/close functions, fade effect etc. Telegram app uses their own custom view for that menu here it is. You can also check source code of their activity here(检查 DrawerLayoutAdapter
、DrawerLayoutAdapter
变量)
首先我使用的是API 28 (Android 9.0) 当我单击 mainActivity 上的菜单按钮时,我希望我的第二个 activity 从左到右出现。 我已经覆盖了 main activity 中的挂起转换,如下所示:
startActivity(myintent);
this.overridePendingTransition(R.anim.left_to_right, R.anim.no_move);
持续时间为 100 毫秒的 left_to_right.xml(这似乎不是 100 毫秒,差不多 1 秒,但动画效果很好):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="100"
android:fromYDelta="0%"
android:fromXDelta="-100%"
android:toXDelta="0%"
android:toYDelta="0%">
</translate>
</set>
和no_move.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%"
android:toYDelta="0%"
android:fromXDelta="0%"
android:toXDelta="0%">
</translate>
</set>
这是我的 theme.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Chess" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="android:windowActivityTransitions">true</item>
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
activity 以我想要的方式开始(动画),但唯一的问题是它的 duration.it 需要 1 秒才能完成翻译。
这里没有额外的代码要提及,我添加的只是 2 个动画文件和覆盖 pendingTranstition
加上在 themes.xml
中将 windowActivityTransition 设置为 True
我想做什么...
我想要的动画就像你在 Telegram 应用程序中单击菜单按钮(在顶部和左侧)时,菜单会顺利显示,我想要这样漂亮的东西。
所以如果有更好的方法来做这些事情,或者如果电报使用另一种方式来制作这个漂亮的动画,请告诉我。
提前致谢。
使用一个 activity
和 DrawerLayout view
for that left menu. It has open/close functions, fade effect etc. Telegram app uses their own custom view for that menu here it is. You can also check source code of their activity here(检查 DrawerLayoutAdapter
、DrawerLayoutAdapter
变量)