1つのインタフェースで複数のTextViewのランニングライト効果を実現
1481 ワード
TextView原生ランニングライト効果を実現
注意:まずTextViewが不完全なテキストを表示することを保証してこそ効果があります
キー属性
ランニングライト表示に設定
フォーカス取得
繰り返し回数の設定
カスタムTextView
しかし、この方法を使用すると、1つのインタフェースに1つのコントロールしか販売ポイントを持つことができないため、1つのインタフェースには1つのViewだけがランニングライト効果を実現することができます(どの最終申請焦点に依存します).カスタマイズが必要です.
カスタムTextViewのフルコードは次のとおりです.
使用方法:は、 は、
ソースアドレス:https://github.com/puppet16/MarqueeTextView
注意:まずTextViewが不完全なテキストを表示することを保証してこそ効果があります
キー属性
ランニングライト表示に設定
android:ellipsize="marquee"
フォーカス取得
android:focusable="true"
touchによりfocus android:focusableInTouchMode="true"
を得ることができる繰り返し回数の設定
android:marqueeRepeatLimit="marquee_forever"
1行表示テキストandroid:singleLine="true"
以上のプロパティは、xml
ファイルの設定後にプログラムを実行するか、それとも効果が得られないかは、コード内でフォーカスを動的に要求する必要があるため、requestFocus()
メソッドを使用します.カスタムTextView
しかし、この方法を使用すると、1つのインタフェースに1つのコントロールしか販売ポイントを持つことができないため、1つのインタフェースには1つのViewだけがランニングライト効果を実現することができます(どの最終申請焦点に依存します).カスタマイズが必要です.
カスタムTextViewのフルコードは次のとおりです.
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class MarqueeTextView extends TextView {
public MarqueeTextView(Context context) {
super(context);
}
public MarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean isFocused() {
return true;
}
}
使用方法:
xml
ファイルで使用されます.これらのキープロパティは追加されます.requestFocus()
メソッドをコードで呼び出す必要はありません.ソースアドレス:https://github.com/puppet16/MarqueeTextView