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

Android 控件的显示隐藏上下左右移动动画的更多相关文章

  1. wpf image控件循环显示图片 以达到动画效果 问题及解决方案

    1>最初方案: 用wpf的image控件循环显示图片,达到动画效果,其实就是在后台代码动态改变Image.Source的值,关键代码: ; i < ; i++)//六百张图片 { Bitm ...

  2. Android控件_TextView(显示文本框控件)

    一.TextView控件的常用属性  1.android:id——控件的id   2.android:layout_width——设置控件的宽度 wrap_content(包裹实际文本内容) fill ...

  3. Android控件重叠显示小记

    方案一 利用布局控件显示优先级 在xml中RelativeLayout,FrameLayout,靠后的控件显示在上层. 利用margin属性 margin属性可以控制控件间的距离,属性值为正值时,越大 ...

  4. winfrom 控件的显示隐藏方法

    使用Panel作为容器 Panel2.Visible = true; //显示 Panel1.Visible = false; //隐藏

  5. HTML5学习总结-10 Android 控件WebView显示网页

    WebView可以使得网页轻松的内嵌到app里,还可以直接跟js相互调用. webview有两个方法:setWebChromeClient 和 setWebClient 1)setWebClient: ...

  6. Android控件显示和隐藏

    Android控件都有visibility属性,该属性有三个可能值:visible.invisible.gone.可以通过预设或是Java程序控制这些控件的显示或隐藏. 一.在XML配置文件设置 可见 ...

  7. [Android Pro] android控件ListView顶部或者底部也显示分割线

    reference to  :  http://blog.csdn.net/lovexieyuan520/article/details/50846569 在默认的Android控件ListView在 ...

  8. Silverlight Visifire控件 .net后台控制aspx页面控件的显示与隐藏,动态给控件赋值,选定默认值的设定

    .net后台代码: 控件的显示与隐藏: this.dateStart.Visibility = Visibility.Collapsed;//不显示控件 this.dateYear.Visibilit ...

  9. 安卓,网页控件,显示网页 Android, web controls, display web pages

    安卓,网页控件,显示网页Android, web controls, display web pages 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq ...

随机推荐

  1. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

  2. 有关bat的一些代码

    1.if语句    @echo off     if exist E:\aa.dat dir C: >> E:\ff.txt       pause     type E:\ff.txt ...

  3. python3的基础练习题

    1. 执行 Python 脚本的两种方式 1)/usr/bin/python3 xx.py 2)python3 xx.py #注xx.py需要在内容里面调用由什么解释器执行 2. 简述位.字节的关系 ...

  4. jquery ripples水波纹效果( 涟漪效果)

    这个效果是我从bootstrap-material-design上面分离下来的,bootstrap-material-design的一些组件样式我不太不喜欢,但是非常喜欢这个水波纹效果,所以就有了这篇 ...

  5. Ubuntu 14.04 LTS 安装 spark 1.6.0 (伪分布式)-26号开始

    需要下载的软件: 1.hadoop-2.6.4.tar.gz 下载网址:http://hadoop.apache.org/releases.html 2.scala-2.11.7.tgz 下载网址:h ...

  6. HTML颜色、超链接设置

    <html> <head> <title>显示的页面选项卡标题</title> <style type="text/css"& ...

  7. Google 地图 API V3 针对移动设备进行开发

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  8. 为什么为 const 变量重新赋值不是个静态错误

    const 和 let 的唯一区别就是用 const 声明的变量不能被重新赋值(只读变量),比如像下面这样就会报错: const foo = 1 foo = 2 // TypeError: Assig ...

  9. hadoop集群安装故障解决

    nodemanager进程解决:http://blog.csdn.net/baiyangfu_love/article/details/13504849 编译安装:http://blog.csdn.n ...

  10. IOS系统基础知识

    在iOS应用中,每个程序得main函数中都调用了UIApplicationMain函数. 1 2 3 4 5 6 int main(int argc, char *argv[])  {      @a ...