mar*_*yam 1 xml animation android android-fragments
我在我的应用程序中使用导航组件。我为片段事务设置了向上/向下滑动动画。但我没有得到想要的结果。我想要的行为是:当新片段(A)替换为前一个片段(B)时,前一个片段保持固定(没有动画)和新的片段从上到上下降,当用户按下返回按钮时,片段 B 从上向下滑动,片段 A 保持固定。我目前得到的行为:当新片段(A)替换为前一个片段(B)时,前一个片段也移动了,当用户按下后退按钮时,片段 A 也移动了。这是我使用过的四个动画文件:enter_from_up.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="-100%" android:toYDelta="0%"
android:duration="350" />
Run Code Online (Sandbox Code Playgroud)
exit_from_down.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="100%"
android:duration="350" />
Run Code Online (Sandbox Code Playgroud)
enter_from_down.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="100%" android:toYDelta="0%"
android:duration="350" />
Run Code Online (Sandbox Code Playgroud)
exit_from_up.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="-100%"
android:duration="350" />
</set>
Run Code Online (Sandbox Code Playgroud)
这是我的导航图的代码:
<action
android:id="@+id/action_welcomeFragment_to_signUpOneFragment" app:destination="@id/signUpOneFragment"
app:enterAnim="@anim/enter_from_down"
app:exitAnim="@anim/exit_from_up"
app:popEnterAnim="@anim/enter_from_up"
app:popExitAnim="@anim/exit_from_down"/>
Run Code Online (Sandbox Code Playgroud)
小智 5
我有一个类似的问题,这是我找到的解决方案:代表前景片段的进入动画的动画(“slide_up”),代表前景片段的退出动画的动画(“slide_down”)和动画( "stationary") 表示背景片段的退出和进入动画的动画。
幻灯片_up.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%" />
Run Code Online (Sandbox Code Playgroud)
slide_down.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%" />
Run Code Online (Sandbox Code Playgroud)
固定.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime" />
Run Code Online (Sandbox Code Playgroud)
nav_graph.xml(部分):
<action
android:id="@+id/action_from_backgroundFragment_to_ForegroundFragment"
app:destination="@id/foregroundFragment"
app:enterAnim="@anim/slide_up"
app:exitAnim="@anim/stationary"
app:popEnterAnim="@anim/stationary"
app:popExitAnim="@anim/slide_down" />
Run Code Online (Sandbox Code Playgroud)
也许这可以帮助你!
| 归档时间: |
|
| 查看次数: |
716 次 |
| 最近记录: |