Implementation and problem summary of Android marquee
The effect of a running horse lamp is the effect of scrolling in the control when the text exceeds the space that the control can hold.
The precondition for displaying the running lantern effect is that your text content is longer than the external component of the displayed text, that is, the external component cannot completely display the internal text content.
TextView:
Android: singleLine = trueandroid: ellipsize = marqueeandroid: focusableInTouchMode = trueandroid: focusable = trueandroid: marqueeRepeatLimit = marquee_forever
However, when you need to scroll all the text, other controls may obtain the focus. In this way, you need to implement the custom control and then achieve the effect that TextView is always in the scroll state.
Package com. xxx. test2; import android. content. context; import android. graphics. rect; import android. util. attributeSet; import android. widget. textView; public class MyTextView extends TextView {public MyTextView (Context context, AttributeSet attrs) {super (context, attrs);} protected void onFocusChanged (boolean focused, int direction, Rect succeeded) {if (focused) super. onFocusChanged (focused, direction, previuslyfocusedrect);} @ Overridepublic void onWindowFocusChanged (boolean focused) {if (focused) super. onWindowFocusChanged (focused) ;}@ Overridepublic boolean isFocused () {return true; // always returns true, pretending that this control has always been getting focus }}Then, use the custom control in the layout.
How to Implement custom components Reference URL: http://blog.csdn.net/jjwwmlp456/article/details/410766
Appendix:Http://www.cnblogs.com/Gaojiecai/archive/2013/06/18/3142783.html
The link above discusses the relationship between the attributes android: clickable = true and (android: focusable = true, android: focusableInTouchMode = true.
In the TextView class, there are two rows:
boolean clickable = focusable; boolean longClickable = focusable;
Clickable is attached with the value of focusable during initialization. However, there is still a piece of code below:
for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case com.android.internal.R.styleable.View_focusable: focusable = a.getBoolean(attr, focusable); break; case com.android.internal.R.styleable.View_clickable: clickable = a.getBoolean(attr, clickable); break; case com.android.internal.R.styleable.View_longClickable: longClickable = a.getBoolean(attr, longClickable); break; } } a.recycle(); setFocusable(focusable); setClickable(clickable);TextView cannot be clicked by default. Many articles have said that configuration in xml files
android:clickable=true
You can click it.
However, this problem occurs:
Set TextView in xml
Test in MainActivity:
Package com. xxx. test2; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. textView; import android. widget. toast; public class MainActivity extends Activity {TextView tv1; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); final TextView tv1 = (TextView) findViewById (R. id. textView1); Toast. makeText (MainActivity. this, duang .. + tv1.isClickable (), 0 ). show (); tv1.setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {Toast. makeText (MainActivity. this, I was clicked + tv1.isClickable (), 0 ). show ();}});}}Result: duang .. false
Guess: A click event is defined for TextView. when clicked, The isClickable value of TextView is changed, but whether it is clicked determines whether a click event is generated, so there will be a bit of conflict. To be resolved, I hope the great gods will be able to solve the problem.