{"id":719,"date":"2023-02-26T15:26:01","date_gmt":"2023-02-26T07:26:01","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=719"},"modified":"2023-04-29T17:14:50","modified_gmt":"2023-04-29T09:14:50","slug":"android-textview-text-italic","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/android-textview-text-italic\/","title":{"rendered":"Android TextView\u6587\u5b57\u503e\u659c"},"content":{"rendered":"<p>\u9700\u6c42\uff1aTextView\u7684\u6587\u5b57\u503e\u659c\u4e00\u5b9a\u7684\u89d2\u5ea6<\/p>\n<h2>\u81ea\u5b9a\u4e49TextView<\/h2>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">public class RotateTextView extends ThemedTextView {\n    private static final int DEFAULT_DEGREES = 0;\n\n    private int mDegrees;\n\n    public RotateTextView(Context context) {\n        super(context, null);\n    }\n\n    public RotateTextView(Context context, AttributeSet attrs) {\n        super(context, attrs, android.R.attr.textViewStyle);\n        this.setGravity(Gravity.CENTER);\n        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RotateTextView);\n        mDegrees = a.getInteger(R.styleable.RotateTextView_degree, DEFAULT_DEGREES);\n        a.recycle();\n    }\n\n    @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n        setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());\n    }\n\n    @Override\n    protected void onDraw(Canvas canvas) {\n        canvas.save();\n        canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());\n        canvas.rotate(mDegrees, this.getWidth() \/ 2f, this.getHeight() \/ 2f);\n        super.onDraw(canvas);\n        canvas.restore();\n    }\n\n    public void setDegrees(int degrees) {\n        mDegrees = degrees;\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;  \n&lt;resources&gt;  \n    &lt;declare-styleable name=&quot;RotateTextView&quot;&gt;  \n        &lt;attr name=&quot;degree&quot; format=&quot;integer&quot; \/&gt;  \n    &lt;\/declare-styleable&gt;  \n&lt;\/resources&gt;<\/code><\/pre>\n<h2>\u4f7f\u7528RotateTextView<\/h2>\n<h3>xml<\/h3>\n<pre><code class=\"language-xml\">&lt;cn.appblog.lib.ui_widget.common.RotateTextView\n    android:id=&quot;@+id\/text&quot;\n    android:layout_width=&quot;30dp&quot;\n    android:layout_height=&quot;30dp&quot;\n    android:layout_marginTop=&quot;2dp&quot;\n    app:degree=&quot;-50&quot;\n    android:textColor=&quot;#F7F7F7&quot;\n    android:textSize=&quot;13sp&quot;\n    \/&gt;<\/code><\/pre>\n<h3>java<\/h3>\n<pre><code class=\"language-java\">RotateTextView mTextView = (RotateTextView) findViewById (R.id.text);  \nmText.setDegrees(10);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\uff1aTextView\u7684\u6587\u5b57\u503e\u659c\u4e00\u5b9a\u7684\u89d2\u5ea6 \u81ea\u5b9a\u4e49TextView public class RotateTe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119],"tags":[],"class_list":["post-719","post","type-post","status-publish","format-standard","hentry","category-android-ui"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=719"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/719\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}