材料设计中的动画对用户的操作给予了反馈,并且在与应用交互时提供了持续的可见性。材料主题提供了一些按钮动画和活动过渡,Android 5.0允许你自定义动画并且可以创建新的动画:

    Touch Feedback
    Circular Reveal
    Activity Transitions
    Curved Motion
    View State Changes

 

自定义触摸反馈

 

在用户与UI元素交互时,从接触的角度来看,材料设计中的触摸反馈提供了瞬间的视觉确认。按钮的默认触摸动画使用了新的RippleDrawable类,使得按钮采用涟漪效果在不同的状态之间过渡。

在大多数情况下,你应该像下面那样在xml中通过设置视图背景来应用这个功能:

  • ?android:attr/selectableItemBackground用于有界涟漪效果。
  • ?android:attr/selectableItemBackgroundBorderless用于拓展到视图外面的涟漪效果。这个效果将被绘制并局限于此视图具有非空背景的最近的你控件中。

注意:selectableItemBackgroundBorderless是API 21中的新属性。

另外,你也可以通过使用ripple元素的xml资源来定义RippleDrawable

你可能给RippleDrawable对象布置颜色。要想改变默认的触摸反馈颜色,得使用该主题的android:colorControlHighlight属性。

 

使用揭露效果

 

在你想要显示或者隐藏一组UI元素时,揭露动画向用户提供了持续地可见性。ViewAnimationUtils.createCircularReveal()方法使你在揭露或隐藏视图时产生一个裁剪圈似的动画。

使用如下效果来揭露之前不可见的视图:

 1 // previously invisible view
 2 View myView = findViewById(R.id.my_view);
 3 // get the center for the clipping circle
 4 int cx = (myView.getLeft() + myView.getRight()) / 2;
 5 int cy = (myView.getTop() + myView.getBottom()) / 2;
 6 // get the final radius for the clipping circle
 7 int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
 8 // create the animator for this view (the start radius is zero)
 9 Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
10 // make the view visible and start the animation
11 myView.setVisibility(View.VISIBLE);
12 anim.start();
View Code

相关文章: