安卓实现文字(TextView)旋转,包括文字角标

实现方案

通过TextView的rotation属性设置旋转角度并实现文字角标.

  • 效果图


  • 代码
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello"
        android:layout_margin="30dp"
        android:rotation="45"/>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello"
        android:layout_margin="30dp"
        android:rotation="90"/>

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello"
        android:layout_margin="30dp"
        android:rotation="-45"/>

<RelativeLayout
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:background="@drawable/shape_rec_blue">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="5dp"
            android:layout_marginRight="-20dp"
            android:background="#FA871E"
            android:gravity="center"
            android:paddingLeft="20dp"
            android:paddingTop="2dp"
            android:paddingRight="20dp"
            android:paddingBottom="2dp"
            android:rotation="45"
            android:text="Hello"
            android:textColor="#FFFFFF"
            android:textSize="12sp"/>
</RelativeLayout>

Demo源代码

https://github.com/cxyzy1/textViewDemos.git

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容