TextView rotation 旋转

问题

很多情况下都会遇到如下样式的界面
这里写图片描述
其他的地方没有难度,麻烦的在于右上角那个角标。
那个赠送四个月的字如何显示?

方案

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的数值,修正一下位置即可。

疑问

暂没有测试点击区域的问题,这种旋转是不是会和补间动画一样,不实际改变控件,而只是视觉上改变了?
根据蓝图的样式,应该是类似于补间动画。
测试完了,再补测试结果。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值