Android开发 之 揭露动画
来源:互联网 发布:淘宝违规处理怎么处理 编辑:程序博客网 时间:2024/05/10 02:07
揭露动画
当您显示或隐藏一组 UI 元素时,揭露动画可为用户提供视觉连续性。
ViewAnimationUtils.createCircularReveal()
方法让您能够为裁剪区域添加动画以揭露或隐藏视图。看代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/rl" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#FF0"> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal"> <ImageButton android:id="@+id/ib01" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/shape_r" android:layout_margin="20dp" android:onClick="button" /> <ImageButton android:id="@+id/ib02" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/shape_red" android:layout_margin="20dp" android:onClick="button" /> <ImageButton android:id="@+id/ib03" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/shape_blue" android:layout_margin="20dp" android:onClick="button" /> </LinearLayout></LinearLayout>
package th.zxq.com.quxianyundong;import android.animation.Animator;import android.animation.AnimatorListenerAdapter;import android.graphics.Color;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.view.ViewAnimationUtils;import android.widget.RelativeLayout;/** * Created by Administrator on 2017/7/24. */public class JieLouActivity extends AppCompatActivity { private RelativeLayout relativeLayout; private boolean b=false; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_jl); relativeLayout = (RelativeLayout) findViewById(R.id.rl); } public void button(View view) { switch (view.getId()) { case R.id.ib01: if(!b) { setposition(relativeLayout); b=true; }else { inde(relativeLayout); b=false; } break; case R.id.ib02: setposition2(relativeLayout); break; case R.id.ib03: setposition3(relativeLayout,view); break; } } public void setposition(View myView) { int cx = (myView.getLeft() + myView.getRight()) / 2; int cy = (myView.getTop() + myView.getBottom()) / 2; int finalRadius = Math.max(myView.getWidth(), myView.getHeight()); Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius); myView.setVisibility(View.VISIBLE); myView.setBackgroundColor(Color.GREEN); anim.setDuration(1000); anim.start(); } public void setposition2(View myView) { int cx = (myView.getLeft() + myView.getRight()) / 2; int cy = 0; int finalRadius = Math.max(myView.getWidth(), myView.getHeight()); Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius); myView.setVisibility(View.VISIBLE); myView.setBackgroundColor(Color.RED); anim.setDuration(1000); anim.start(); } public void setposition3(View myView,View view) { int[] location=new int[2]; view.getLocationInWindow(location); int cx = location[0]+view.getWidth()/2; int cy = location[1]; int finalRadius = Math.max(myView.getWidth(), myView.getHeight()); Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius); myView.setVisibility(View.VISIBLE); myView.setBackgroundColor(Color.BLUE); anim.setDuration(1000); anim.start(); } /** * 隐藏 * @param myView */ public void inde(final View myView) { int cx = (myView.getLeft() + myView.getRight()) / 2; int cy = (myView.getTop() + myView.getBottom()) / 2; int initialRadius = myView.getWidth(); Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); myView.setVisibility(View.INVISIBLE); } }); anim.start(); }}
以上的三个圆是用shape画的,形状颜色可以自行修改
ps;这个揭露动画如果执行完后是隐藏view的话,需要注意一点,隐藏view的上层显示的view将会一并呗隐藏掉。不可见。
阅读全文
1 0
- Android开发 之 揭露动画
- Android Activity转场 -- 揭露动画
- Android动画学习(六)之View揭露效果和SurfaceView实现动画
- Android Reveal Animation(揭露动画)实现
- Android CircularReveal揭露动画三种实现
- Android 创建CircularReveal揭露动画的实现
- android之动画开发
- Android开发之动画
- 揭露动画ViewAnimationUtils.createCircularReveal()
- Android(开发):动画之Frame动画
- Android开发之Frame动画(帧动画)
- Android开发之自定义动画
- Android开发之动画实现
- android开发系列之动画
- Android开发之Viewpager动画
- android开发之动画效果
- Android开发 之 帧动画
- Android开发 之 属性动画
- Android 中的动画基础笔记
- 【HDU
- HDU 2669 Romantic(扩展欧几里德)
- poj 3494 Largest Submatrix of All 1’s(单调栈)
- 欢迎使用CSDN-markdown编辑器
- Android开发 之 揭露动画
- 有用的英文播客
- Eclipse导入项目时出现感叹号"!"该如何解决
- Access denied for user 'root'@'localhost' (using password:YES)
- Kotlin使用
- FPGA利用待分频时钟实现任意分频
- 机器学习-->python常用知识点
- markdown(editor.md)编辑器-图片上传
- postgresql查看数据库占用的物理存储空间大小