从应用程序小部件创建缩放动画

4

一些应用小部件在从小部件启动活动时使用了makeScaleUpAnimation(在JellyBean 4.1中引入)。当您无法从小部件提供程序访问视图时,如何实现这一点?

是否有办法获取整个应用小部件视图或类似的东西?我找不到解决方案。

ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(view, 0, 0,
        view.getWidth(), view.getHeight());
  // Request the activity be started, using the custom animation options.
  startActivity(new Intent(MainActivity.this, AnimationActivity.class),
        opts.toBundle());

我正在从我的小部件中打开短信收件箱。
Intent inboxIntent = new Intent(Intent.ACTION_MAIN);
                inboxIntent.setType("vnd.android-dir/mms-sms");
                int flags = Intent.FLAG_ACTIVITY_NEW_TASK |

                        Intent.FLAG_ACTIVITY_SINGLE_TOP |          

                        Intent.FLAG_ACTIVITY_CLEAR_TOP;
                inboxIntent.setFlags(flags);

                context.startActivity(inboxIntent);
1个回答

4

您的应用程序应该调用getIntent().getSourceBounds()方法来获取此信息。


没有从一个活动开始活动,但你是对的,那就是关键。这是我的最终代码。创建一个空视图感觉不对,但它可以工作。`View view = new View(context); view.setLayoutParams(new LayoutParams(0,0)); ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(view, intent.getSourceBounds().left, intent.getSourceBounds().top, intent.getSourceBounds().width(), intent.getSourceBounds().height()); context.startActivity(threadIntent, opts.toBundle());` - Thoast83
1
这是一个奇怪的函数。如果查看源代码,传入的“View”仅用于获取您的软件包名称(从视图的上下文中)并将边界从客户端坐标转换为屏幕坐标。似乎最好将该参数更改为“Context”,并要求使用屏幕坐标开始。由于您传递的“View”在屏幕上没有位置(从未附加到窗口),因此您的坐标最终被视为屏幕坐标(这很好,因为这就是您从“getSourceBounds()”中获得的内容)。 - j__m
1
基本上你的解决方案比你想象的还要更像一个hack,但它能够工作,也没有其他版本的方法。 - j__m

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接