android数字滚动效果实现

上一篇 / 下一篇  2015-11-04 17:15:21 / 个人分类:step by step android测试

ps:做的过程中又熟悉了的几个关键属性:
android:gravity=“center” 居中
android:includeFontPadding=“false" 去掉text size自带的padding值
android:layout_toRightOf="@id/XXX”LinearLayout中以另外一个元素为基准来设置padding值

以下是正文:
onFinishInflate中对动画进行定义赋值,一个滚出去的动画,一个滚上来的动画。在oncreate方法里面对需要滚动的元素设置动画效果。
<?xml version="1.0"encoding="utf-8"?><setxmlns:android="http://schemas.android.com/apk/res/android"]]>    
<translateandroid:fromYDelta="100%p"android:toYDelta="0"android:duration="300"/>   <alphaandroid:fromAlpha="0.0"android:toAlpha="1.0"android:duration="300"/></set]]>

<?xml version="1.0"encoding="utf-8"?><setxmlns:android="http://schemas.android.com/apk/res/android"]]>    
<translateandroid:fromYDelta="0"android:toYDelta="-100%p"android:duration="300"/>  
  
<alphaandroid:fromAlpha="1.0"android:toAlpha="0.0"android:duration="300"/></set]]>
上下滚动的话,需要定义2个一模一样的textview,但是通过GONE与VISIBLE来控制textview的显示区域。元素就会交替展示啦。
自己定义事件来调用滚动的函数就好。      
private voidshowCountAnimation() {    
//第一个可见时    
if(A.getVisibility() == View.VISIBLE) {         if(A.getAnimation() ==mInAnimation)           {            
      A.clearAnimation();        
      }        
      A.startAnimation(mOutAnimation);                A.setVisibility(View.GONE);        
      if(B.getAnimation() ==mOutAnimation)           {            
      B.clearAnimation();        
      }        
      B.setText("1111");                           B.startAnimation(mInAnimation);                 B.setVisibility(View.VISIBLE);    
else{        
      if(A.getAnimation() ==mOutAnimation)           {            
      A.clearAnimation();        
      }        
      A.setText("2222");                              A.startAnimation(mInAnimation);                 A.setVisibility(View.VISIBLE);        
      if(B.getAnimation() ==mInAnimation)      {            
      B.clearAnimation();        
      }
      B.startAnimation(mOutAnimation);                 B.setVisibility(View.GONE);    
}
}

TAG: Android android

 

评分:0

我来说两句

Open Toolbar