
在Material Design视频中,视图非常顺畅地展开和收缩.我试图在旧的Android API的日子里实现这一点,它真的很昂贵而且速度很慢.
AndroID-L中是否有任何新API可以实现这些效果?
视频效果为http://www.youtube.com/watch?v=Q8TXgCzxEnw#t=26
解决方法:
您可以使用androID-L中的新动画API轻松创建您在此视频中看到的大部分效果.
揭示效果
您可以为剪切圆设置动画以显示或隐藏视图.
这是您在视频中单击“播放”按钮时看到的内容.该按钮可展开并显示媒体播放器.
用于显示隐藏视图的代码(source)
// prevIoUsly invisible vIEwVIEw myVIEw = findVIEwByID(R.ID.my_vIEw);// get the center for the clipPing circleint cx = (myVIEw.getleft() + myVIEw.getRight()) / 2;int cy = (myVIEw.gettop() + myVIEw.getBottom()) / 2;// get the final radius for the clipPing circleint finalRadius = myVIEw.getWIDth();// create and start the animator for this vIEw// (the start radius is zero)ValueAnimator anim = VIEwAnimationUtils.createCircularReveal(myVIEw, cx, cy, 0, finalRadius);anim.start();如果您按照上述链接,您可以找到隐藏视图的代码.
活动进入和退出过渡
您可以指定视图进入或退出场景的方式.
当前支持的转换是爆炸,滑动和淡入淡出.还支持任何扩展androID.Transition.Visibility的转换.
整个视频中都可以看到很多例子.
爆炸退出过渡代码(source)
// insIDe your activitygetwindow().requestFeature(Window.FEATURE_CONTENT_TransitionS);// set an exit Transitiongetwindow().setExitTransition(new Explode());活动共享元素转换
您可以指定两个活动之间共享的元素如何在它们之间进行转换.
支持的转换是:
> changeBounds – 动画显示目标视图的布局边界的更改.
> changeClipBounds – 动画显示目标视图剪辑边界的更改.
> changetransform – 动画目标视图的缩放和旋转变化.
> changeImagetransform – 为图像视图设置动画大小和比例类型的更改.
要进行共享元素转换,您需要执行以下 *** 作:(source)
>以您的风格启用窗口内容转换.
>在您的样式中指定共享元素过渡.
>将转换定义为XML资源.
>使用androID:vIEwname属性为两个布局中的共享元素指定一个公用名.
>使用ActivityOptions.makeSceneTransitionAnimation方法.
// get the element that receives the click eventfinal VIEw imgContainerVIEw = findVIEwByID(R.ID.img_container);// get the common element for the Transition in this activityfinal VIEw androIDRobotVIEw = findVIEwByID(R.ID.image_small);// define a click ListenerimgContainerVIEw.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw vIEw) { Intent intent = new Intent(this, Activity2.class); // create the Transition animation - the images in the layouts // of both activitIEs are defined with androID:vIEwname="robot" ActivityOptions options = ActivityOptions .makeSceneTransitionAnimation(this, androIDRobotVIEw, "robot"); // start the new activity startActivity(intent, options.toBundle()); }});我还没想到的一个动画是同一活动中的扩展/合约动画,可以在日历应用程序中看到.
我唯一可以说的是他们正在使用高程,因为我们可以看到阴影.我会尝试破解它,看看我是否可以重新创建它.
总结以上是内存溢出为你收集整理的android – 顺利扩展和收缩视图全部内容,希望文章能够帮你解决android – 顺利扩展和收缩视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)