实现TextView滚动

来源:互联网 发布:数据分析入门 python 编辑:程序博客网 时间:2024/06/05 00:27

实现TextView滚动功能。

自定义TextView.

/* * Copyright (C) 2013 Capital Alliance Software LTD (Pekall) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.pekall.fmradio;import android.content.Context;import android.util.AttributeSet;import android.widget.TextView;/** * Marquee Text to make it scrolling even without real focus */public class MarqueeText extends TextView {    public MarqueeText(Context arg0, AttributeSet arg1, int arg2) {        super(arg0, arg1, arg2);    }    public MarqueeText(Context context, AttributeSet attrs) {        super(context, attrs);    }    public MarqueeText(Context context) {        super(context);    }    @Override    public boolean isFocused() {        return true;//自定义的目的这里是关键    }}

            <com.pekall.fmradio.MarqueeText                android:id="@+id/info_text"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_alignParentBottom="true"                android:layout_centerHorizontal="true"                android:layout_marginBottom="20dip"                android:ellipsize="marquee"                android:focusable="true"                android:focusableInTouchMode="true"                android:gravity="center"                android:marqueeRepeatLimit="marquee_forever"                android:paddingLeft="10dip"                android:paddingRight="10dip"                android:paddingTop="2dip"                android:singleLine="true"                android:textColor="#FF92c2f3"                android:textSize="20sp"                android:textStyle="bold" />

marqueeRepeatLimit

singleLine

focusable

ellipsize

focusableInTouchMode


0 0