转型机器人片段向上滑动 [英] Transition android fragment slide up

查看:136
本文介绍了转型机器人片段向上滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段是替代另一个片段。我想指定的动画。但动画将被忽略。

I have a fragment that is to replace another fragment. I want to specify the animation. But the animation is ignored.

transaction.replace(R.id.my_fragment, newFrag);
transaction.addToBackStack(null);
transaction.setCustomAnimations(R.anim.slide_in_up, R.anim.slide_out_up);

slide_in_up

<?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%p"
    android:toYDelta="100%p" />

slide_out_up

<?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%p"
    android:toYDelta="0%p" />

所有我真正想要实现的是新的片段,从底部滑动。我的动画被忽略。什么是code失踪?

All I am really trying to achieve is for the new fragment to slide in from the bottom. My animations are ignored. What is the code missing?

推荐答案

它已经一段时间了,因为有人问这个问题,但这里是其他人来到这里的答案:

It's been some time since this question was asked but here is an answer for other people coming here:

e1da是正确的,只要是setCustomAnimation()调用面前被称为替代()。否则,动画将不会显示。
第二个问题是,你可能正在使用,不能与视图的动画动画天然片段。
请使用以下文件:

e1da is right insofar as that setCustomAnimation() call has to be called before replace(). Otherwise the animation will not show.
The second problem is that you probably are using native fragments that cannot be animated with the view animations.
Use the following files:

slide_in_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
    <objectAnimator
        android:duration="500"
        android:propertyName="y"
        android:valueFrom="1280"
        android:valueTo="0"
        android:valueType="floatType" />
</set>

slide_out_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
    <objectAnimator
        android:duration="500"
        android:propertyName="y"
        android:valueFrom="0"
        android:valueTo="-1280"
        android:valueType="floatType" />
</set>

这一点解释:
你一方面和财产动画,另一方面本土片段观看动画来区分的支持片段。

A little explanation:
You have to differentiate between view animation for support fragments on one hand and property animation for native fragments on the other hand.

查看动画:
是动画欣赏到pre-的Andr​​oid 3.0的方式。样品code这是slide_in.xml和slide_up.xml由user3093402

View animation:
Is the pre-android 3.0 way to animate views. Sample code for this is the slide_in.xml and slide_up.xml by user3093402

<?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%p"
android:toYDelta="100%p" />

值得一提的,你不能观看动画动画片段。唯一的例外是从支持库(android.support.v4.app.Fragment)片段

It is worth mentioning you cannot animate fragments with view animation. The exception to this are fragments from the support library (android.support.v4.app.Fragment).

属性动画
这也是Android 3.0后的动画对象的方式。它也被宣布为.xml文件,但使用了valueAnimator标签(objectAnimator延伸valueAnimator)。实例是在问题的答案。 这是怎样的方式原始片段(android.app.Fragment)可以是动态的。

Property animation
This is the way to animate objects after android 3.0. It is also declared as .xml files but makes use of the "valueAnimator" tag (objectAnimator extends valueAnimator). Examples are in the answer to the question. This is the way how native fragments (android.app.Fragment) can be animated.

另请参阅:

  • http://developer.android.com/guide/topics/graphics/overview.html
  • swap fragment in an activity via animation

希望这有助于

Hope this helps,
Kai

编辑:正如拉斐尔罗耶-里瓦德固定屏幕尺寸为不好的做法。这将是更好地使用一个常数从OS像 getWindowManager()。getDefaultDisplay()。getMetrics(指标).xdpi (见 DisplayMetrics )。但是,我没有做任何Android开发有一段时间了,所以我不知道是哪一个。

As pointed out by Raphael Royer-Rivard the fixed screen size is bad practice. It would be better to use a constant from the OS like in getWindowManager().getDefaultDisplay().getMetrics(metrics).xdpi (see DisplayMetrics). But I haven't done any Android development for some time so I don't know which one.

这篇关于转型机器人片段向上滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆