zoukankan      html  css  js  c++  java
  • Android 控件的显示隐藏上下左右移动动画

    一、利用Android提供的左右移动工具类:AnimationUtils

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    LinearLayout ll_first = (LinearLayout) findViewById(R.id.ll_first);
    LinearLayout ll_second = (LinearLayout) findViewById(R.id.ll_second);
    ll_first.setVisibility(View.GONE);
    ll_second.setVisibility(View.VISIBLE);
    // 向右边移出
    ll_first.setAnimation(AnimationUtils.makeOutAnimation(thistrue));
    // 向右边移入
    ll_second.setAnimation(AnimationUtils.makeInAnimation(thistrue));
     
     
     
     
    ll_first.setVisibility(View.VISIBLE);
    ll_second.setVisibility(View.GONE);
    // 向左边移入
    ll_first.setAnimation(AnimationUtils.makeInAnimation(thisfalse));
    // 向左边移出
    ll_second.setAnimation(AnimationUtils.makeOutAnimation(thisfalse));

    二、用TranslateAnimation添加动画

    先写一个AnimationUtil工具类:这里仅提供上下移动效果

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    public class AnimationUtil {
        private static final String TAG = AnimationUtil.class.getSimpleName();
     
        /**
         * 从控件所在位置移动到控件的底部
         *
         * @return
         */
        public static TranslateAnimation moveToViewBottom() {
            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.setDuration(500);
            return mHiddenAction;
        }
     
        /**
         * 从控件的底部移动到控件所在位置
         *
         * @return
         */
        public static TranslateAnimation moveToViewLocation() {
            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.setDuration(500);
            return mHiddenAction;
        }
    }

    隐藏的时候设置下动画就可以了

    1
    2
    3
    4
    ll_first.setVisibility(View.GONE);
    ll_second.setVisibility(View.VISIBLE);
    ll_first.setAnimation(AnimationUtil.moveToViewBottom());
    ll_second.setAnimation(AnimationUtil.moveToViewLocation());

    博客原文地址:http://www.cnblogs.com/liqw/p/4602876.html

     
    分类: android
  • 相关阅读:
    应用程序调试技术视频观看指南
    应用程序调试技术视频各集技术概述
    使用gettext技术为ASP.NET网站实现国际化支持
    反调试技术二
    VC 6中使用不同调用规范的函数在符号文件里的表示方式
    使用allpairs自动设计组合测试用例
    BDD测试演示视频
    bitset学习笔记 & 洛谷 P3674 小清新人渣的本愿(莫队、bitset)
    牛客挑战赛53 B.简单的序列(bitset,哥德巴赫猜想)
    P6775 [NOI2020] 制作菜品(dp,bitset)
  • 原文地址:https://www.cnblogs.com/wangfeng520/p/6178134.html
Copyright © 2011-2022 走看看