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( 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工具類:這里僅提供上下移動效果

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM