我正在使用Jetpack Navigation组件来导航片段,我在res目录中创建了一个动画,并添加了这个animation-transition
:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="600"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXDelta="100%"
android:toXDelta="0%" />
</set>
将此动画设置为导航组件中打开的片段的进入动画:
![enter image description here](https://istack.dev59.com/grcIM.webp)
调用后:
findNavController().navigate(R.id.reg2Fragment)
我仍然没有得到我手动动画的效果,只有默认的淡入淡出效果。
我在整个项目主题中使用Material Io设计,并且这是我的依赖项:
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.activity:activity-ktx:1.3.1"
implementation "androidx.fragment:fragment-ktx:1.3.6"
implementation platform('com.google.firebase:firebase-bom:28.4.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
// for Jet-Pack-Navigation-Component
implementation 'androidx.navigation:navigation-fragment-ktx'
implementation 'androidx.navigation:navigation-ui-ktx'
这里是导航图:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/reg1Fragment">
<fragment
android:id="@+id/reg1Fragment"
android:name="com.example.authapp.uiRegistration.Reg1Fragment"
tools:layout="@layout/fragment_reg1"
android:label="Reg1Fragment" >
<action
android:id="@+id/action_reg1Fragment2_to_reg2Fragment"
app:destination="@id/reg2Fragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/slide_out_bottom"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/reg2Fragment"
android:name="com.example.authapp.uiRegistration.Reg2Fragment"
tools:layout="@layout/fragment_reg2"
android:label="Reg2Fragment" >
<action
android:id="@+id/action_reg2Fragment_to_reg3Fragment"
app:destination="@id/reg3Fragment"
app:enterAnim="@anim/nav_default_enter_anim" />
</fragment>
<fragment
android:id="@+id/reg3Fragment"
android:name="com.example.authapp.uiRegistration.Reg3Fragment"
android:label="fragment_reg3"
tools:layout="@layout/fragment_reg3" >
<action
android:id="@+id/action_reg3Fragment_to_userProfile"
app:destination="@id/userProfile"
app:popUpTo="@id/userProfile" />
</fragment>
<activity
android:id="@+id/userProfile"
android:name="com.example.authapp.UserProfile"
android:label="activity_user_profile"
tools:layout="@layout/activity_user_profile" />
</navigation>
请有经验的人帮我解决这个问题。
谢谢