【问题标题】:Material Design layout animationMaterial Design 布局动画
【发布时间】:2014-08-09 15:38:42
【问题描述】:

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

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

【问题讨论】:

  • 您想在列表视图项上应用此动画吗?还是只是简单的看法?
  • 发布一个正是你想要的视频肯定会有所帮助。 adb shell screenrecord?
  • @Vikram 好主意,会的。

标签: android animation material-design


【解决方案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你不能只在DialogFragment或PopupWindow中注入动态ObjectAnimator)

【讨论】:

    【解决方案2】:

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

    为此,请实现以下代码:

    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 开发者Animation 参考和View Animation API 指南中获取更多信息。

    【讨论】:

      猜你喜欢
      • 2016-09-05
      • 2015-05-07
      • 2015-01-17
      • 2015-07-03
      • 2016-02-14
      • 1970-01-01
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多