|
- 实现跑马灯效果的TextView
! w) B. s" T( o/ A, Y. W+ O
) j- R7 _2 G5 y- O4 `- import android.content.Context;
! M7 r$ S0 `( o7 s - import android.util.AttributeSet;
l2 L4 A# `( J4 _4 b$ l" Q3 e - import android.widget.TextView;) E* l! J( @( |& Z6 W; R0 |
5 N. K$ D- V6 x% L' h# d- /**
, B: {2 L6 C* _ - * 实现跑马灯效果的TextView) D6 a8 G" s A8 f" S
- */
6 ]- `% c) _% M$ S. o" { - public class MarqueeTextView extends TextView {( d& `; k# d; D' W1 h
- private boolean mNeedFocus;0 Y" m2 x$ ?9 }1 G9 m8 Q
- public MarqueeTextView(Context context) {
4 }9 c' g0 c$ A - super(context);
: {3 b6 Q" L7 n5 u+ z' |8 S - }
^" f5 H- E; v: N+ W' z - public MarqueeTextView(Context context, AttributeSet attrs) {
4 C, I- `2 b* M2 S+ G& x9 K6 P - super(context, attrs);' H; d+ i0 G/ h \
- }
b( K% y9 [6 p1 s Y* f7 K# g - public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
0 P5 Y5 D8 O" m8 u9 v7 Y# x - super(context, attrs, defStyleAttr);" M/ `- H8 n' V% Z& j/ J! S3 O! n+ F
- }6 u' `" N/ Y) N8 f, P' f- [
- //返回textview是否处在选中的状态
" ~1 w( w" M: U; i2 _ - //而只有选中的textview才能够实现跑马灯效果
6 Y0 E9 t* z. {* d! d' O; k' a - @Override: P5 k& {. i/ C# p( |7 S3 M2 D- S
- public boolean isFocused() {
+ ~! S3 W) y2 _) |7 i$ E; k x - if (mNeedFocus) {8 ?4 k6 ?/ g( {8 y3 ]/ m- v9 L
- return false;4 w3 ]( ]% ^7 g5 L
- }7 ]5 D; H+ N1 f0 Q
- return super.isFocused();
4 m! {0 a( J& O3 q( c+ Z; _3 s" ^; y+ H - }
! y: h; H9 |' N
: i5 A' f/ q& E' v9 h$ m7 L- public void setNeedFocus(boolean needFocus) {
2 n, A; H% {& f# o9 K4 j. S - mNeedFocus = needFocus;
* j1 ^3 w$ |1 `+ @( p; N, X- O- j- v - }
9 T4 m \# ]) T. T% w7 j& k3 H2 p - }
: x2 e) ~3 A; S0 I/ O' N/ i
复制代码 |
|