7

Android L 的想法之一是弹出窗口需要从用户点击屏幕的位置开始出现。
例如,在 Chrome Beta (@time * 5) 中:
Chrome 测试版

这个想法是能够使视图从任何枢轴点(不仅仅是溢出按钮的预定位置)增长有没有人能够做到这一点或目前不可行?

4

2 回答 2

1

似乎没有干净的方法可以做到这一点。
我发现的唯一可行的选择是编写 4 个不同的 xml 动画(对于 4 个角,如果您想允许居中生长,则更多),所有 ScaleAnimations 从 0 到 1,每个具有不同的枢轴点(4 个角)。

然后,使用DialogFragment

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) 
{
    final Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.getWindow().getAttributes().windowAnimations = 
         R.style.downRightCornerAnimation;
    //instead of referring to R.*, call a method to get the specific
    //resource you need for a given start position
    return dialog;
}

这种动画的一个例子:

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/linear_interpolator"
       android:fromXScale="0.0"
       android:toXScale="1.0"
       android:fromYScale="0.0"
       android:toYScale="1.0"
       android:fillAfter="false"
       android:duration="200" 
       android:pivotX = "0%"
       android:pivotY = "100%"/>   

它非常笨拙和hacky,但我不认为SDK为我们提供了更好的工具来做到这一点(AFAIK你不能只ObjectAnimatorDialogFragmentor中注入动态PopupWindow

于 2014-10-06T00:00:43.607 回答
0

好吧,我想在一般视图中制作动画应该适合你。

为此,请实现以下代码:

RecyclerView view = (RecyclerView) findViewById(R.id.your_view);
Animation appear = AnimationUtils.loadAnimation(this, R.anim.appear);
apear.startAnimation(view);

然后,在您的 res/anim 文件夹中(如果不存在则创建它),创建一个名为 append.xml 的 xml 文件并放入以下代码:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:android:fromXScale="0"
        android:toXScale="1.0"
        android:fromYScale="0"
        android:toYScale="1.0"
        android:duration="1000" />
</set>

更改适合您目的的值。

您可以在 android 开发者动画参考和查看动画API 指南中获得更多信息。

于 2014-10-04T10:35:29.793 回答