一、利用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

更多相关文章

  1. android笔记一 控件属性
  2. Android 时间对象操作工具类
  3. android中进度条控件
  4. android中设置控件获得焦点
  5. Android aapt 工具介绍(转载)
  6. 时钟控件布局
  7. Android 打开关闭闪光灯工具类
  8. android Notification 工具类
  9. android简陋的开发工具

随机推荐

  1. Android Notes 05 - Tasks and Back Stac
  2. android传送照片到FTP服务器
  3. android 抽奖盘动画 自定义View
  4. Android Bitmap与DrawAble与byte[]与Inpu
  5. Android之使用Activity与Fragment通信
  6. Android之水平ProgressBar多彩背景颜色
  7. Android中图片的处理(放大缩小,去色,转换格
  8. Sina微博的开发心得-1 logo界面
  9. android 获取农历日期和天干、地支
  10. android 实现流媒体播放远程mp3文件代码