android动画特效之解决解决移动后闪烁现象,解决输入法弹出后位置回复原状,解决两个动画叠加
2013-07-19 17:44
489 查看
以下代码实现的效果是:
BoundOpenView从居中移动到顶部,移动完后,BoundSendView从隐藏变为显示,并从顶部移动BoundOpenView下方20dp处,同时透明度慢慢增加。
BoundOpenView从居中移动到顶部,移动完后,BoundSendView从隐藏变为显示,并从顶部移动BoundOpenView下方20dp处,同时透明度慢慢增加。
private void BoundOpenViewAnimation() { Log.i(TAG, "BoundOpenViewAnimation"); final int top = BoundOpenView.getTop() - DensityUtil.dip2px(mContext, 20); final int height = BoundOpenView.getHeight(); TranslateAnimation animation = new TranslateAnimation(0, 0, 0, 0 - top); animation.setDuration(200);// 设置动画持续时间 BoundOpenView.clearAnimation(); BoundOpenView.setAnimation(animation); animation.setFillAfter(true); // ** 开始动画 *//* animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { //BoundOpenView.clearAnimation();// 解决移动后闪烁现象 TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0); BoundOpenView.setAnimation(anim); //解决输入法弹出后位置回复原状 RelativeLayout.LayoutParams lp = new RelativeLayout .LayoutParams(BoundOpenView.getWidth(),BoundOpenView.getHeight()); //lp.topMargin=DensityUtil.dip2px(mContext, 20); lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); BoundOpenView.setLayoutParams(lp); int move = height + DensityUtil.dip2px(mContext, 20); BoundSendViewAnimation(move); } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationStart(Animation animation) { } }); animation.startNow(); } private void BoundSendViewAnimation(int move) { Log.i(TAG, "move:"+move); Animation translateanimation = new TranslateAnimation(0, 0, 0, move); translateanimation.setDuration(400);// 设置动画持续时间 Animation alphaAnimation=new AlphaAnimation(0.01f,1.0f); alphaAnimation.setDuration(500);// 设置动画持续时间 //动画叠加 AnimationSet set=new AnimationSet(true); //创建动画集对象 set.addAnimation(translateanimation); //添加位置变化动画 set.addAnimation(alphaAnimation); //添加尺寸变化动画 set.setFillAfter(true); //停留在最后的位置 set.setFillEnabled(true); BoundSendView.clearAnimation(); BoundSendView.setAnimation(set); //设置动画 BoundSendView.setVisibility(View.VISIBLE); // ** 开始动画 *//* set.setAnimationListener(new AnimationListener() { @Override public void onAnimationEnd(Animation animation) { TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0); BoundSendView.setAnimation(anim); RelativeLayout.LayoutParams lp = new RelativeLayout .LayoutParams(BoundSendView.getWidth(),BoundSendView.getHeight()); lp.addRule(RelativeLayout.BELOW,R.id.bound_open_view); lp.topMargin=DensityUtil.dip2px(mContext, 20); BoundSendView.setLayoutParams(lp); } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } }); set.startNow(); //启动动画 }DensityUtil类:
import android.content.Context; public class DensityUtil { /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } /** * 根据手机的分辨率从 px(像素) 的单位 转成为 dp */ public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } }
相关文章推荐
- android动画特效之解决解决移动后闪烁现象,解决输入法弹出后位置回复原状,解决两个动画叠加
- 解决Android EditText获得焦点之后无法弹出软键盘输入法
- Android输入法弹出时把布局顶上去和登录按钮顶上去的解决方法
- Android解决输入法自动弹出方法大全
- Android动画:解决通过View.getY()获取初始位置为0的问题
- Android移动view动画问题 关于view的位置移动了,但view里面绑定的监听器还在原位
- android帧动画,移动位置,缩放,改变透明度等动画解说
- Android 解决弹出输入法时布局闪动问题
- Android 输入法键盘和activity页面遮挡和自动弹出问题解决
- android edittext 点击两次才弹出输入法的解决方法之一
- Android: 解决动画完成后位置恢复到初始位置的问题
- Android实现输入法弹出时把布局顶上去和登录按钮顶上去的解决方法
- [Android] InputMethodManager内存泄露现象及解决 输入法造成的内存泄露
- Android移动view动画问题 关于view的位置移动了,但view里面绑定的监听器还在原位
- Android仿微信清理内存图表动画(解决surfaceView屏幕闪烁问题)demo实例详解
- Android之解决输入法软键盘弹出挤压屏幕或覆盖控件问题
- phonegap android 输入法弹出会遮盖表单框的解决办法
- 解决 android 输入法弹出输入框被遮挡的问题
- android 使用动画 Button移动后不响应点击事件的解决办法
- android 输入法弹出键盘把listview顶上去,保留顶部标题栏位置不动