{"id":147,"date":"2023-02-18T20:40:08","date_gmt":"2023-02-18T12:40:08","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=147"},"modified":"2023-02-18T20:44:11","modified_gmt":"2023-02-18T12:44:11","slug":"android-running-lamp-not-moving-solution","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/android-running-lamp-not-moving-solution\/","title":{"rendered":"\u89e3\u51b3Android\u8dd1\u9a6c\u706f\u4e0d\u52a8\u95ee\u9898"},"content":{"rendered":"<h2>\u5e03\u5c40\u914d\u7f6e<\/h2>\n<p>\u9996\u5148\u6765\u770b\u4e00\u4e0b\u8bf7\u7684\u5e03\u5c40\u5427\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\n    style=&quot;@style\/LayoutFFStyle&quot;\n    android:orientation=&quot;vertical&quot; \n    android:background=&quot;#F6F4EE&quot;&gt;\n\n    &lt;RelativeLayout \n        style=&quot;@style\/LayoutFWStyle&quot;\n        android:layout_gravity=&quot;center_vertical&quot;\n        android:gravity=&quot;center_vertical&quot;\n        android:background=&quot;#EEEEEE&quot;\n        android:paddingTop=&quot;5dip&quot;\n        android:paddingBottom=&quot;5dip&quot;&gt;\n\n        &lt;LinearLayout \n            style=&quot;@style\/LayoutWFStyle&quot;\n            android:orientation=&quot;horizontal&quot;\n            android:layout_alignParentLeft=&quot;true&quot;\n            android:layout_margin=&quot;10dip&quot;&gt;\n\n            &lt;TextView \n                android:layout_width=&quot;100dip&quot;\n                android:layout_height=&quot;wrap_content&quot;\n                android:textColor=&quot;#000000&quot;\n                android:text=&quot;AppBlog.CN APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2, AppBlog.CN APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2&quot;\n                android:ellipsize=&quot;marquee&quot;   \n                android:focusable=&quot;true&quot;   \n                android:marqueeRepeatLimit=&quot;marquee_forever&quot;   \n                android:focusableInTouchMode=&quot;true&quot;   \n                android:scrollHorizontally=&quot;true&quot;\n                android:textSize=&quot;18sp&quot;\n                android:singleLine=&quot;true&quot;\n                android:layout_marginLeft=&quot;5dip&quot;\/&gt;\n\n            &lt;TextView \n                android:id=&quot;@+id\/search_result_list_item_percapita&quot;\n                style=&quot;@style\/LayoutWWStyle&quot;\n                android:textColor=&quot;#000000&quot;\n                android:paddingLeft=&quot;5dip&quot;\n                android:textSize=&quot;18sp&quot;\n                android:gravity=&quot;center_vertical&quot;\/&gt;\n        &lt;\/LinearLayout&gt;\n\n        &lt;LinearLayout \n            style=&quot;@style\/LayoutWFStyle&quot;\n            android:orientation=&quot;horizontal&quot;\n            android:layout_margin=&quot;10dip&quot;\n            android:layout_alignParentRight=&quot;true&quot;&gt;\n\n            &lt;TextView \n                style=&quot;@style\/LayoutWWStyle&quot;\n                android:gravity=&quot;center_vertical&quot;\n                android:paddingRight=&quot;5dip&quot;\n                android:text=&quot;386m&quot;\/&gt;\n\n            &lt;ImageView \n                style=&quot;@style\/LayoutWWStyle&quot;\n                android:layout_gravity=&quot;center_vertical&quot;\n                android:src=&quot;@drawable\/arrow_right_gray&quot;\/&gt;\n        &lt;\/LinearLayout&gt;\n    &lt;\/RelativeLayout&gt;\n\n    &lt;Gallery\n        android:id=&quot;@+id\/search_result_foot_gallery&quot; \n        style=&quot;@style\/LayoutFWStyle&quot;\n        android:paddingTop=&quot;10dip&quot;\n        android:paddingBottom=&quot;10dip&quot;\n        android:spacing=&quot;10dip&quot;\n        android:scrollbars=&quot;none&quot;\n        android:fadingEdge=&quot;none&quot;\n        android:unselectedAlpha=&quot;1&quot;\/&gt;\n&lt;\/LinearLayout&gt;<\/code><\/pre>\n<p>\u8bf4\u660e\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u5e03\u5c40\u662f\u5728ListView\u4e2ditem\uff0c\u5728adapter\u53bb\u5f15\u7528\u7684\uff0c\u8dd1\u9a6c\u706f\u6700\u540e\u5c31\u4e0d\u6eda\u52a8\u3002\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<h2>\u8bbe\u7f6e\u7126\u70b9<\/h2>\n<pre><code class=\"language-xml\">&lt;TextView\n    android:layout_width=&quot;100dip&quot;\n    android:layout_height=&quot;wrap_content&quot;\n    android:textColor=&quot;#000000&quot;\n    android:text=&quot;AppBlog.CN APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2, AppBlog.CN APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2&quot;\n    android:ellipsize=&quot;marquee&quot;   \n    android:focusable=&quot;true&quot;\n    android:marqueeRepeatLimit=&quot;marquee_forever&quot;   \n    android:focusableInTouchMode=&quot;true&quot;   \n    android:scrollHorizontally=&quot;true&quot;\n    android:textSize=&quot;18sp&quot;\n    android:singleLine=&quot;true&quot;\n    android:hapticFeedbackEnabled=&quot;true&quot;\n    android:layout_marginLeft=&quot;5dip&quot;&gt;\n\n    &lt;requestFocus\/&gt;\n&lt;\/TextView&gt;<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u5728ListView\u5e03\u5c40\u4e0b\u4e0d\u592a\u9760\u8c31\uff0c\u5982\u679c\u80fd\u591f\u5728\u5f15\u7528\u8fd9\u4e2a\u5e03\u5c40\u6587\u4ef6\u4e2d\u53bb\u8bbe\u7f6e\u7126\u70b9\u8bdd\u5e94\u8be5\u53ef\u4ee5\u7528\uff0c\u4f46\u662f\u6ca1\u6709\u8bd5\u8fc7\u3002<\/p>\n<h2>\u91cd\u5199TextView<\/h2>\n<pre><code class=\"language-java\">import android.content.Context;\nimport android.util.AttributeSet;\nimport android.widget.TextView;\n\n\/**\n * \u89e3\u51b3\u8dd1\u9a6c\u706f\u4e0d\u52a8\u7684\u95ee\u9898\n *\/\npublic class ScrollForeverTextView extends TextView {  \n\n    public ScrollForeverTextView(Context context) {  \n        super(context);  \n    }  \n\n    public ScrollForeverTextView(Context context, AttributeSet attrs) {  \n        super(context, attrs);  \n    }  \n\n    public ScrollForeverTextView(Context context, AttributeSet attrs,  \n            int defStyle) {  \n        super(context, attrs, defStyle);  \n    }  \n\n    @Override  \n    public boolean isFocused() {  \n        return true;  \n    }  \n\n}<\/code><\/pre>\n<pre><code class=\"language-xml\">&lt;cn.appblog.widget.ScrollForeverTextView \n    android:layout_width=&quot;100dip&quot;\n    android:layout_height=&quot;wrap_content&quot;\n    android:textColor=&quot;#000000&quot;\n    android:text=&quot;AppBlog.CN APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2, AppBlog.CN APP\u5f00\u53d1\u6280\u672f\u535a\u5ba2&quot;\n    android:ellipsize=&quot;marquee&quot;   \n    android:focusable=&quot;true&quot;   \n    android:marqueeRepeatLimit=&quot;marquee_forever&quot;   \n    android:focusableInTouchMode=&quot;true&quot;   \n    android:scrollHorizontally=&quot;true&quot;\n    android:textSize=&quot;18sp&quot;\n    android:singleLine=&quot;true&quot;\n    android:layout_marginLeft=&quot;5dip&quot;\/&gt;<\/code><\/pre>\n<h2>\u81ea\u5b9a\u4e49\u63a7\u4ef6<\/h2>\n<pre><code class=\"language-java\">import android.content.Context;\nimport android.graphics.Canvas;\nimport android.graphics.Paint;\nimport android.os.Parcel;\nimport android.os.Parcelable;\nimport android.util.AttributeSet;\nimport android.view.View;\nimport android.view.View.OnClickListener;\nimport android.widget.TextView;\n\nimport com.lianlianpay.common.config.Constants;\nimport com.lianlianpay.common.utils.android.NLog;\n\n\/**\n * \u5355\u884c\u6587\u672c\u8dd1\u9a6c\u706f\u63a7\u4ef6\n *\/\npublic class AutoScrollTextView extends TextView implements OnClickListener {\n    public final static String TAG = AutoScrollTextView.class.getSimpleName();\n\n    private float textLength = 0f;\/\/ \u6587\u672c\u957f\u5ea6\n    private float viewWidth = 0f;\n    private float step = 0f;\/\/ \u6587\u5b57\u7684\u6a2a\u5750\u6807\n    private float y = 0f;\/\/ \u6587\u5b57\u7684\u7eb5\u5750\u6807\n    private float temp_view_plus_text_length = 0.0f;\/\/ \u7528\u4e8e\u8ba1\u7b97\u7684\u4e34\u65f6\u53d8\u91cf\n    private float temp_view_plus_two_text_length = 0.0f;\/\/ \u7528\u4e8e\u8ba1\u7b97\u7684\u4e34\u65f6\u53d8\u91cf\n    public boolean isStarting = false;\/\/ \u662f\u5426\u5f00\u59cb\u6eda\u52a8\n    private Paint paint = null;\/\/ \u7ed8\u56fe\u6837\u5f0f\n    private CharSequence text = &quot;&quot;;\/\/ \u6587\u672c\u5185\u5bb9\n    private float speed = 0.5f;\n    private int textColor = 0xFF000000;\n\n    public int getTextColor() {\n        return textColor;\n    }\n\n    public void setTextColor(int color) {\n        this.textColor = color;\n    }\n\n    public float getSpeed() {\n        return speed;\n    }\n\n    public void setSpeed(float speed) {\n        this.speed = speed;\n    }\n\n    public AutoScrollTextView(Context context) {\n        super(context);\n        initView();\n    }\n\n    public AutoScrollTextView(Context context, AttributeSet attrs) {\n        super(context, attrs);\n        initView();\n    }\n\n    public AutoScrollTextView(Context context, AttributeSet attrs, int defStyle) {\n        super(context, attrs, defStyle);\n        initView();\n    }\n\n    \/** *\/\n    \/**\n     * \u521d\u59cb\u5316\u63a7\u4ef6\n     *\/\n    private void initView() {\n        setOnClickListener(this);\n    }\n\n    \/**\n    \/**\n     * \u6587\u672c\u521d\u59cb\u5316\uff0c\u6bcf\u6b21\u66f4\u6539\u6587\u672c\u5185\u5bb9\u6216\u8005\u6587\u672c\u6548\u679c\u7b49\u4e4b\u540e\u90fd\u9700\u8981\u91cd\u65b0\u521d\u59cb\u5316\u4e00\u4e0b!\n     *\/\n    public void init(float width\/*WindowManager windowManager*\/) {\n        NLog.i(Constants.TAG, &quot;width: &quot; + width);\n        text = super.getText();\n        paint = super.getPaint();\n        \/\/ Paint paint = new Paint();\n        text = getText().toString();\n        textLength = paint.measureText(text.toString());\n        \/\/ viewWidth = getWidth();\n        \/\/ if (viewWidth == 0) {\n        \/\/     if (windowManager != null) {\n        \/\/         Display display = windowManager.getDefaultDisplay();\n        \/\/         viewWidth = display.getWidth();\n        \/\/     }\n        \/\/ }\n        viewWidth = width;\n        step = textLength;\n        temp_view_plus_text_length = viewWidth + textLength;\n        temp_view_plus_two_text_length = viewWidth + textLength * 2;\n        y = getTextSize() + getPaddingTop();\n        paint.setColor(textColor);\n    }\n\n    @Override\n    public Parcelable onSaveInstanceState() {\n        Parcelable superState = super.onSaveInstanceState();\n        SavedState ss = new SavedState(superState);\n\n        ss.step = step;\n        ss.isStarting = isStarting;\n\n        return ss;\n    }\n\n    @Override\n    public void onRestoreInstanceState(Parcelable state) {\n        if (!(state instanceof SavedState)) {\n            super.onRestoreInstanceState(state);\n            return;\n        }\n        SavedState ss = (SavedState) state;\n        super.onRestoreInstanceState(ss.getSuperState());\n\n        step = ss.step;\n        isStarting = ss.isStarting;\n    }\n\n    public static class SavedState extends BaseSavedState {\n        public boolean isStarting = false;\n        public float step = 0.0f;\n\n        SavedState(Parcelable superState) {\n            super(superState);\n        }\n\n        @Override\n        public void writeToParcel(Parcel out, int flags) {\n            super.writeToParcel(out, flags);\n            out.writeBooleanArray(new boolean[]{isStarting});\n            out.writeFloat(step);\n        }\n\n        public static final Parcelable.Creator&lt;SavedState&gt; CREATOR = new Parcelable.Creator&lt;SavedState&gt;() {\n\n            public SavedState[] newArray(int size) {\n                return new SavedState[size];\n            }\n\n            @Override\n            public SavedState createFromParcel(Parcel in) {\n                return new SavedState(in);\n            }\n        };\n\n        private SavedState(Parcel in) {\n            super(in);\n            boolean[] b = null;\n            in.readBooleanArray(b);\n            if (b != null &amp;&amp; b.length &gt; 0)\n                isStarting = b[0];\n            step = in.readFloat();\n        }\n    }\n\n    \/**\n     * \u5f00\u59cb\u6eda\u52a8\n     *\/\n    public void startScroll() {\n        isStarting = true;\n        invalidate();\n    }\n\n    \/**\n     * \u505c\u6b62\u6eda\u52a8\n     *\/\n    public void stopScroll() {\n        isStarting = false;\n        invalidate();\n    }\n\n    @Override\n    public void onDraw(Canvas canvas) {\n        \/\/super.onDraw(canvas);\n\n        canvas.drawText(text, 0, text.length(), temp_view_plus_text_length - step, y, paint);\n        if (!isStarting) {\n            return;\n        }\n        step += speed;\n        if (step &gt; temp_view_plus_two_text_length)\n            step = textLength;\n        invalidate();\n    }\n\n    @Override\n    public void onClick(View v) {\n        if (isStarting)\n            stopScroll();\n        else\n            startScroll();\n    }\n\n}<\/code><\/pre>\n<pre><code class=\"language-java\">marquee = (AutoScrollTextView) findViewById(R.id.marquee);  \n\/\/marquee.setText(String.format(getResources().getString(R.string.marquee0),Consts.termno,&quot;2015-12-28&quot;));  \nmarquee.setText(&quot;\u4e0a\u8bc1\u6307\u65703000.15 6.81(0.37%) \u6df1\u5733\u6210\u63073000.15 6.81(0.37%)&quot;);  \n\/\/marquee.setTextColor(0xffff0000);\/\/\u6ce8\u610f\uff1a\u989c\u8272\u5fc5\u987b\u5728\u8fd9\u91cc\u8bbe\u7f6e\uff0cxml\u4e2d\u8bbe\u7f6e\u65e0\u6548\uff01\u9ed8\u8ba4\u9ed1\u8272\u3002  \n\/\/\u5982\u679c\u60f3\u6539\u53d8\u8dd1\u9a6c\u706f\u7684\u6587\u5b57\u5185\u5bb9\u6216\u8005\u6587\u5b57\u6548\u679c\uff0c\u5219\u5728\u8c03\u7528\u5b8csetText\u65b9\u6cd5\u4e4b\u540e\uff0c\u9700\u8981\u518d\u8c03\u7528\u4e00\u4e0binit(width)\u65b9\u6cd5\uff0c\u91cd\u65b0\u8fdb\u884c\u521d\u59cb\u5316\u548c\u76f8\u5173\u53c2\u6570\u7684\u8ba1\u7b97\u3002  \nmarquee.setSpeed(1.5f);  \n marquee.init(width);\/\/width\u901a\u5e38\u5c31\u662f\u5c4f\u5e55\u5bbd\uff01  \nmarquee.startScroll();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5e03\u5c40\u914d\u7f6e \u9996\u5148\u6765\u770b\u4e00\u4e0b\u8bf7\u7684\u5e03\u5c40\u5427\uff1a &lt;?xml version=&quot;1.0&quot; enco [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-android-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/147","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=147"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}