欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-13 22:33:37
...

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

 /**
     * 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());