android 中view控件的隐藏与显示动作

xiaoxiao2021-02-27  332

注释已经写得很清楚了。这个只是一些常规的显示与隐藏动作,没有左右移动,左右移动安卓自带很容易百度到,下面直接看代码。

/** * view隐藏动作 */ public class AnimationUtil { /** * 从控件所在位置移动到控件顶部 * * @return */ public TranslateAnimation moveToViewSelfToTop() { TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f); mHiddenAction.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { isGestureEnabled = true; } @Override public void onAnimationRepeat(Animation animation) { } }); mHiddenAction.setDuration(500); return mHiddenAction; } /** * 从控件的顶部移动到控件所在位置 * * @return */ public TranslateAnimation moveToViewTopToSelf() { TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f); mHiddenAction.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { isGestureEnabled = true; } @Override public void onAnimationRepeat(Animation animation) { } }); mHiddenAction.setDuration(500); return mHiddenAction; } /** * 从控件所在位置移动到控件底部 */ public TranslateAnimation moveToViewSelfToBottom() { TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f); mHiddenAction.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { isGestureEnabled = true; } @Override public void onAnimationRepeat(Animation animation) { } }); mHiddenAction.setDuration(500); return mHiddenAction; } /** * 从控件的底部移动到控件所在位置 * * @return */ public TranslateAnimation moveToViewBottomToSelf() { TranslateAnimation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); mHiddenAction.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { isGestureEnabled = true; } @Override public void onAnimationRepeat(Animation animation) { } }); mHiddenAction.setDuration(500); return mHiddenAction; } }调用:

linearLayout_measure.setAnimation(animationUtil.moveToViewBottomToSelf()); linearLayout_search.setAnimation(animationUtil.moveToViewSelfToTop()); linearLayout_mainbottom.setAnimation(animationUtil.moveToViewSelfToBottom()); relativeLayout_measure.setAnimation(animationUtil.moveToViewTopToSelf());

转载请注明原文地址: https://www.6miu.com/read-1542.html

最新回复(0)