{"id":508,"date":"2020-05-22T14:00:15","date_gmt":"2020-05-22T06:00:15","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=508"},"modified":"2020-05-26T16:03:47","modified_gmt":"2020-05-26T08:03:47","slug":"android-%e8%87%aa%e5%ae%9a%e7%be%a9%e8%b7%91%e9%a6%ac%e7%87%88","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/android-%e8%87%aa%e5%ae%9a%e7%be%a9%e8%b7%91%e9%a6%ac%e7%87%88\/","title":{"rendered":"Android \u81ea\u5b9a\u7fa9\u8dd1\u99ac\u71c8 MarqueeTextView"},"content":{"rendered":"<h3>1.\u81ea\u5b9a\u7fa9View<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">import android.content.Context\nimport android.graphics.Rect\nimport android.text.TextUtils\nimport android.util.AttributeSet\nimport androidx.appcompat.widget.AppCompatTextView\n\nclass MarqueeTextView(context: Context, attrs: AttributeSet) : AppCompatTextView(context, attrs) {\n    init {\n        \/\/\u8a2d\u5b9a\u55ae\u884c\n        setSingleLine()\n        \/\/\u8a2d\u5b9a\u8dd1\u99ac\u71c8\n        ellipsize = TextUtils.TruncateAt.MARQUEE\n        \/\/\u7372\u53d6\u7126\u9ede\n        isFocusable = true\n        \/\/-1\u4ee3\u8868\u7121\u9650\n        marqueeRepeatLimit = -1\n        \/\/\u5f37\u5236\u7372\u53d6\u7126\u9ede\n        isFocusableInTouchMode = true\n    }\n\n    \/\/\u6c38\u9060\u70ba\u7126\u9ede\n    override fun isFocused(): Boolean {\n        return true\n    }\n\n    \/\/\u89e3\u6c7aEditText\u6436\u7126\u9ede\n    override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) {\n        if (focused) {\n            super.onFocusChanged(true, direction, previouslyFocusedRect)\n        }\n    }\n\n    \/\/Window\u8207Window\u9593\u7126\u9ede\u767c\u751f\u6539\u8b8a\n    override fun onWindowFocusChanged(hasWindowFocus: Boolean) {\n        if (hasWindowFocus) {\n            super.onWindowFocusChanged(true)\n        }\n    }\n}\n<\/code><\/pre>\n<h3>2.\u5728XML\u8abf\u7528<\/h3>\n<pre><code class=\"language-XML line-numbers\">    &lt;com.fly.githubtestkotlin.MarqueeTextView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:textColor=\"#ff0000\"\n        android:textSize=\"36sp\"\n        android:text=\"\u6211\u662f\u8dd1\u99ac\u71c8 \u4f60\u4e5f\u662f\u8dd1\u99ac\u71c8 \u5927\u5bb6\u90fd\u662f\u8dd1\u99ac\u71c8\"\n        app:layout_constraintEnd_toEndOf=\"parent\"\n        app:layout_constraintStart_toStartOf=\"parent\"\n        app:layout_constraintTop_toTopOf=\"parent\" \/&gt;\n\n<\/code><\/pre>\n<h3>3.\u6548\u679c\u5c55\u793a<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2020\/05\/52.gif\" alt=\"\" \/><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>class MarqueeTextView(context: Context, attrs: AttributeSet) : AppCompatTextView(context, attrs) {<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[5],"tags":[13,15,33],"class_list":["post-508","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-kotlin","tag-view"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=508"}],"version-history":[{"count":3,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/508\/revisions"}],"predecessor-version":[{"id":524,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/508\/revisions\/524"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}