草庐IT

android - Fragment.onCreateAnimator() 的文档在哪里?

coder 2023-06-08 原文

Fragment.onCreateAnimator(int, boolean, int) 的完整文档方法由以下文本组成:

"Called when a fragment loads an animation."

就是这样。参数不做说明。

参数是什么意思? Even the source code doesn't reveal much.

最佳答案

onCreateAnimator 方法很奇怪。 我看到的原型(prototype)是这样的:

public Animator onCreateAnimator(int transit, boolean enter, int nextAnim)

int transit - 过渡类型,正如上面sandrstar所说的

boolean enter - 如果'进入'则为真,否则为假

int nextAnim - 即将播放动画的资源ID。

例如,如果您尝试翻转卡片,from the documentation :

// Create and commit a new fragment transaction that adds the fragment for the back of
// the card, uses custom animations, and is part of the fragment manager's back stack.
BackOfCardFragment backFragment = new BackOfCardFragment();

getFragmentManager()
    .beginTransaction()

    // Replace the default fragment animations with animator resources representing
    // rotations when switching to the back of the card, as well as animator
    // resources representing rotations when flipping back to the front (e.g. when
    // the system Back button is pressed).
    .setCustomAnimations(
         R.animator.card_flip_right_in, R.animator.card_flip_right_out,
         R.animator.card_flip_left_in, R.animator.card_flip_left_out)

    // Replace any fragments currently in the container view with a fragment
    // representing the next page (indicated by the just-incremented currentPage
    // variable).
    .replace(R.id.container_view, backFragment)

    // Add this transaction to the back stack, allowing users to press Back
    // to get to the front of the card.
    .addToBackStack(null)

    // Commit the transaction.
    .commit();

注意:上例中的 R.id.container_view 是包含您要替换的现有 fragment 的 ViewGroup 的 ID。

当执行上述代码时,会调用 onCreateAnimator 方法,nextAnim 参数将是传入 setCustomAnimations 的四个动画 ID 之一() 函数,即R.animator.card_flip_right_in、R.animator.card_flip_right_out...等

一开始这似乎并没有立竿见影的效果,因为它没有为您提供可以附加监听器的实际 Animator 对象的引用。但奇怪的是,您可以直接从 nextAnim 资源中为另一个 Animator 充气,然后将监听器附加到该资源上,奇怪的是,这会在正确的时间触发所有被覆盖的回调:

@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
    Animator animator = null;
    // In this example, i want to add a listener when the card_flip_right_in animation
    // is about to happen.
    if (nextAnim == R.animator.card_flip_right_in) {
        animator = AnimatorInflater.loadAnimator(getActivity(), nextAnim);
        // * Sometimes onCreateAnimator will be called and nextAnim will be 0, 
        //   causing animator to be null.
        // * I wanted to add a listener when the fragment was entering - 
        //   your use case may be different.
        if (animator != null && enter) {

            animator.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                   // Do something when the card flip animation begins
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                   // Do something as soon as the card flip animation is over
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                }

                @Override
                public void onAnimationRepeat(Animator animation) {
                }
            });
        }
    }
    return animator;
}

通过这种方式,您应该能够将监听器添加到 fragment 转换动画器中,就像您自己创建它们一样。

关于android - Fragment.onCreateAnimator() 的文档在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16910510/

有关android - Fragment.onCreateAnimator() 的文档在哪里?的更多相关文章

  1. Matlab imread()读到了什么 (浅显 当复习文档了) - 2

    matlab打开matlab,用最简单的imread方法读取一个图像clcclearimg_h=imread('hua.jpg');返回一个数组(矩阵),往往是a*b*cunit8类型解释一下这个三维数组的意思,行数、数和层数,unit8:指数据类型,无符号八位整形,可理解为0~2^8的数三个层数分别代表RGB三个通道图像rgb最常用的是24-位实现方法,即RGB每个通道有256色阶(2^8)。基于这样的24-位RGB模型的色彩空间可以表现256×256×256≈1670万色当imshow传入了一个二维数组,它将以灰度方式绘制;可以把图像拆分为rgb三层,可以以灰度的方式观察它figure(1

  2. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  3. ruby-on-rails - ActiveRecord::Associations::CollectionProxy 从哪里获取.each 实例方法? - 2

    假设我有模型Topics和Posts,其中Topichas_many:posts和Postbelongs_to:topic。此时我的数据库中已经有了一些东西。如果我进入Rails控制台并输入Topic.find(1).posts我相信我得到了一个CollectionProxy对象。=>#]>我可以对此调用.each以获得枚举器对象。=>#]:each>我对CollectionProxy如何处理.each感到困惑。我意识到它在某些时候是继承的,但我一直在阅读API文档,他们并没有说得很清楚CollectionProxy是从什么继承的,除非我遗漏了一些明显的东西。Thispage似乎并没有

  4. ruby-on-rails - 闪存消息存储在哪里? - 2

    我以为它们存储在cookie中-但不,检查cookie没有任何结果。session也不存储它们。那么,我在哪里可以找到它们?我需要这个来直接设置它们(而不是通过flashhash)。 最佳答案 它们存储在inyoursessionstore.自rails2.0以来的默认设置是cookie存储,但请检查config/initializers/session_store.rb以检查您是否使用默认设置以外的东西。 关于ruby-on-rails-闪存消息存储在哪里?,我们在StackOverf

  5. Ruby 等同于 Sphinx 文档生成器? - 2

    Ruby有一些不错的文档生成器,例如Yard、rDoc,甚至Glyph。问题是Sphinx可以做网站、PDF、epub、LaTex等。它在重组文本中完成所有这些事情。在Ruby世界中有替​​代方案吗?也许是程序的组合?如果我也能使用Markdown就更好了。 最佳答案 自1.0版以来,Sphinx有了“域”的概念,它是从Python和/或C以外的语言标记代码实体(如方法调用、对象、函数等)的方法。有一个rubydomain,所以你可以只使用Sphinx本身。您唯一会缺少的(我认为)是Sphinx使用autodoc从源代码自动创建文档

  6. ruby-on-rails - Ruby 如何知道在哪里可以找到所需的文件? - 2

    这里还有一个新手问题:require'tasks/rails'我在每个Rails项目的根路径中的Rakefile中看到了这一行。我猜这行用于要求vendor/rails/railties/lib/tasks/rails.rb加载所有rake任务:$VERBOSE=nil#LoadRailsrakefileextensionsDir["#{File.dirname(__FILE__)}/*.rake"].each{|ext|loadext}#LoadanycustomrakefileextensionsDir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].so

  7. ruby-on-rails - 在 irb 中阅读文档 - 2

    我怀念ipython的一件事是它有一个?为特定功能挖掘文档的运算符。我知道ruby​​有一个类似的命令行工具,但是我在irb中调用它非常不方便。ruby/irb有类似的东西吗? 最佳答案 Pry是IPython的Ruby版本,它支持?命令来查找有关方法的文档,但语法略有不同:pry(main)>?File.dirnameFrom:file.cinRubyCore(CMethod):Numberoflines:6visibility:publicsignature:dirname()Returnsallcomponentsofthef

  8. ruby - 使用 Nokogiri 和 Ruby 从 html 文档获取链接和 href 文本? - 2

    我正在尝试使用nokogirigem提取页面上的所有url及其链接文本,并将链接文本和url存储在散列中。FooBar我想回去{"Foo"=>"#foo","Bar"=>"#bar"} 最佳答案 这是一个单行:Hash[doc.xpath('//a[@href]').map{|link|[link.text.strip,link["href"]]}]#=>{"Foo"=>"#foo","Bar"=>"#bar"}拆分一点可以说更具可读性:h={}doc.xpath('//a[@href]').eachdo|link|h[link.t

  9. ruby-on-rails - Rubygems - 包在哪里下载? - 2

    当你安装一个新包时,例如,'geminstallfb-graph',文件下载到哪里了? 最佳答案 使用此命令查找特定gem的安装位置:gemwhich例如:gemwhichfb-graph 关于ruby-on-rails-Rubygems-包在哪里下载?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/13200065/

  10. ruby-on-rails - 在 Rails 中向 Integer 类添加方法的最佳位置在哪里? - 2

    在Rails中向整数类添加方法的最佳位置在哪里?我想添加一个to_meters和to_miles方法。 最佳答案 如果您决心使用数字(或整数等)类来进行单位转换,那么至少要在逻辑上做到这一点,并具有一些实际值(value)。首先,创建一个Unit类,用于存储单位类型(米、英尺、肘等)和创建时的值。然后向Numeric添加一堆方法,这些方法对应于单元可以具有的有效值:这些方法将返回一个单元对象,其类型记录为方法名称。Unit类将支持一组to_*方法,这些方法将转换为具有相应单位值的另一种单位类型。这样,您可以执行以下命令:>>x=47

随机推荐