倾斜的TextView

不废话,直接上代码:

package com.shangshaban.zhaopin.views;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;

/**
 * Created by peter on 2016/12/24.
 * 为了预约直播页面,特意重写的TextView
 */

public class ShangshabanRotateTextView extends android.support.v7.widget.AppCompatTextView {
    public ShangshabanRotateTextView(Context context) {
        super(context);
    }

    public ShangshabanRotateTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //倾斜度45,上下左右居中
        canvas.rotate(10, getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        super.onDraw(canvas);
    }
}

然后在布局文件里面正常用就可以了

<com.peter.views.ShangshabanRotateTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/lin_text"
        android:layout_marginRight="75dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/live_yuncai"
        android:gravity="center"
        android:text="要直播\n赶快戳这里" />

搞定!老规矩,上图

《倾斜的TextView》 要直播赶快戳这里效果.png

    原文作者:来自唐朝的栗子
    原文地址: https://www.jianshu.com/p/d45cb0806faa
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞