Android 怎么旋转TextView文字显示方向

Linux大全评论5.8K views阅读模式

在一个项目中,需要旋转TextView的文字显示方向,怎么实现呢?这里提供一种变通的方法来实现该功能:Animation动画,保存动画结束状态来实现该功能。

主要代码如下:

1、定义一个anim xml资源文件rotate_right.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set>  
  3. <rotate xmlns:Android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"    
  4.     android:fromDegrees="0" android:toDegrees="-90" android:duration="0"    
  5.     android:pivotX="50%" android:pivotY="50%" android:repeatCount="0" />    
  6. </set>  

2、设置textview播放动画

  1. private Animation mAnimationRight;  
  2. private TextView mlblRightPhotoNum;  
  3.   
  4. mAnimationRight = AnimationUtils.loadAnimation(mContext, R.anim.rotate_right);  
  5. mAnimationRight.setFillAfter(true);   
  6.   
  7. mlblRightPhotoNum = (TextView) findViewById(R.id.lblRightPhotoNum);  
  8. mlblRightPhotoNum.setAnimation(mAnimationRight);  

总结:主要用到了Animation 的 setFillAfter(boolean b)方法,该方法表示是否保持动画结束时状态;

拓展:

企鹅博客
  • 本文由 发表于 2019年9月8日 02:06:23
  • 转载请务必保留本文链接:https://www.qieseo.com/172077.html

发表评论