Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

Android TextView文字倾斜

需求:TextView的文字倾斜一定的角度

自定义TextView

public class RotateTextView extends ThemedTextView {
    private static final int DEFAULT_DEGREES = 0;

    private int mDegrees;

    public RotateTextView(Context context) {
        super(context, null);
    }

    public RotateTextView(Context context, AttributeSet attrs) {
        super(context, attrs, android.R.attr.textViewStyle);
        this.setGravity(Gravity.CENTER);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RotateTextView);
        mDegrees = a.getInteger(R.styleable.RotateTextView_degree, DEFAULT_DEGREES);
        a.recycle();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.save();
        canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
        canvas.rotate(mDegrees, this.getWidth() / 2f, this.getHeight() / 2f);
        super.onDraw(canvas);
        canvas.restore();
    }

    public void setDegrees(int degrees) {
        mDegrees = degrees;
    }
}
<?xml version="1.0" encoding="utf-8"?>  
<resources>  
    <declare-styleable name="RotateTextView">  
        <attr name="degree" format="integer" />  
    </declare-styleable>  
</resources>

使用RotateTextView

xml

<cn.appblog.lib.ui_widget.common.RotateTextView
    android:id="@+id/text"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_marginTop="2dp"
    app:degree="-50"
    android:textColor="#F7F7F7"
    android:textSize="13sp"
    />

java

RotateTextView mTextView = (RotateTextView) findViewById (R.id.text);  
mText.setDegrees(10);
上一篇 Android Parcelable中枚举的写法
下一篇 Genymotion模拟器无法开启的解决方法