问题
很多情况下都会遇到如下样式的界面
其他的地方没有难度,麻烦的在于右上角那个角标。
那个赠送四个月的字如何显示?
方案
TextView 中在sdk版本 大于2.2 的属性中,增加了一个rotation的属性,可以旋转TextView。(基本上现在基于最低都是4.0,所以畅快的使用就好了)
XML中设置
android:rotation=”45”
java代码中设置
textView.setRotation(45);
坑
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1231230000"
android:textSize="22sp"
android:rotation="45"/>
</LinearLayout>
虽然设置了旋转,但是有一个问题,转出去了,如下图
怎么办?
android:transformPivotY=”25dp”
android:transformPivotX=”15dp”
调整一下TextView 显示的位置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1231230000"
android:textSize="22sp"
android:rotation="45"
android:transformPivotY="25dp"
android:transformPivotX="15dp"/>
</LinearLayout>
原因
从那个蓝图布局下,可以明显看出,其实TextView的控件大小并没有根据设置旋转而自动改变控件宽高,这就导致了,因为旋转是根据控件的中心点开始的,如蓝图模式下显示的TextView的中心点旋转,自然就出去了,这时候调整一下显示的X和Y的数值,修正一下位置即可。
疑问
暂没有测试点击区域的问题,这种旋转是不是会和补间动画一样,不实际改变控件,而只是视觉上改变了?
根据蓝图的样式,应该是类似于补间动画。
测试完了,再补测试结果。