如何使用导航架构组件向变化的 fragment 添加动画?
最佳答案
在导航组件文档( https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing ) 中的部分:在目的地之间创建过渡 (它在文档的末尾附近)您已经详细解释了它。
您可以使用编辑器添加它们,方法是选择所需过渡的箭头,然后在“属性”选项卡的“动画”部分中选择动画。
或者通过引用 xml 文件中的动画,如示例中所示:
<fragment
android:id="@+id/specifyAmountFragment"
android:name="com.example.buybuddy.buybuddy.SpecifyAmountFragment"
android:label="fragment_specify_amount"
tools:layout="@layout/fragment_specify_amount">
<action
android:id="@+id/confirmationAction"
app:destination="@id/confirmationFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
您可以为此动画使用常规动画资源
关于android - 如何使用导航组件向变化的 fragment 添加动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52794596/