在一个项目中,需要旋转TextView的文字显示方向,怎么实现呢?这里提供一种变通的方法来实现该功能:Animation动画,保存动画结束状态来实现该功能。
主要代码如下:
1、定义一个anim xml资源文件rotate_right.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set>
- <rotate xmlns:Android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"
- android:fromDegrees="0" android:toDegrees="-90" android:duration="0"
- android:pivotX="50%" android:pivotY="50%" android:repeatCount="0" />
- </set>
2、设置textview播放动画
- private Animation mAnimationRight;
- private TextView mlblRightPhotoNum;
- mAnimationRight = AnimationUtils.loadAnimation(mContext, R.anim.rotate_right);
- mAnimationRight.setFillAfter(true);
- mlblRightPhotoNum = (TextView) findViewById(R.id.lblRightPhotoNum);
- mlblRightPhotoNum.setAnimation(mAnimationRight);
总结:主要用到了Animation 的 setFillAfter(boolean b)方法,该方法表示是否保持动画结束时状态;
拓展: