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

    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(this, true));    // 向右边移入    ll_second.setAnimation(AnimationUtils.makeInAnimation(this, true));                ll_first.setVisibility(View.VISIBLE);    ll_second.setVisibility(View.GONE);    // 向左边移入    ll_first.setAnimation(AnimationUtils.makeInAnimation(this, false));    // 向左边移出    ll_second.setAnimation(AnimationUtils.makeOutAnimation(this, false));

二、用TranslateAnimation添加动画

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

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;    }}

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

                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

转载于:https://www.cnblogs.com/liqw/p/4602876.html

更多相关文章

  1. 三、安卓UI学习(1)
  2. Android(安卓)matrix 控制图片的旋转、缩放、移动
  3. android用户界面之按钮(Button)教程实例汇
  4. 在Fragment中设置控件点击方法,执行失败。
  5. TabHost与RadioGroup结合完成的菜单【带效果图】5个Activity
  6. Android常用控件
  7. android用户界面-组件Widget-画廊视图Gallery
  8. 总目录
  9. android 单元测试

随机推荐

  1. Android 源代码目录结构1 - bionic
  2. Gallery的使用
  3. android Handler,Looper,Message三者关系
  4. android中的http框架,使其更加简单易用
  5. Android NDK1、Android NDK带来什么
  6. 《Android 4 高级编程》试读
  7. 使用Kotlin开发Android基础介绍
  8. 【Android】TextView 属性详解
  9. 吹毛求疵android画图板(1)
  10. 介绍Android拍照,录像开发的相关东东