The so-called marquee effect is the effect of scrolling within the control when the text exceeds the space that the control can hold.
The prerequisite for displaying the marquee effect is that your text content is longer than the external component that displays the text, that is, the external component is not able to fully display the internal text content.
TextView set the following properties to achieve the marquee effect:
Android:singleline= "true" android:ellipsize= "marquee" android:focusableintouchmode= "true" android:focusable= "true "Android:marqueerepeatlimit=" Marquee_forever "<!--This property is not required, you can specify a specific number of scrolls, or you can use the default--
But when text is required to scroll all the time, it is possible for other controls to get focus. This requires implementing a custom control and then achieving the effect that TextView has been in a scrolling 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 previouslyfocusedrect) {if (focused) Super.onfocuschanged (focused, direction, previouslyfocusedrect);} @Overridepublic void Onwindowfocuschanged (Boolean focused) {if (focused) super.onwindowfocuschanged (focused);} @Overridepublic Boolean isFocused () {return true;//always returns true, pretending that the control has been getting the focus}}
Then use the custom control in the layout
<com.xxx.test2.mytextviewandroid:id= "@+id/textview2" android:layout_width= "80DP" android:layout_height= "Wrap_ Content "android:ellipsize=" marquee "android:focusable=" true "Android:focusableintouchmode=" true "Android: Singleline= "true" android:text= "play, play, play, play, play, play, play"/>
How to implement a custom component reference URL: http://blog.csdn.net/jjwwmlp456/article/details/410766
attached: http://www.cnblogs.com/Gaojiecai/archive/2013/06/18/3142783.html
The above link discusses the relationship of the two properties under Android:clickable= "true" and (android:focusable= "true", android:focusableintouchmode= "true").
In the TextView class, there are two lines:
Boolean clickable = focusable; Boolean longclickable = focusable;
Clickable is appended with the value of focusable at initialization time. But there is another piece of code in the back:
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);
By default, TextView cannot be clicked. Many articles say that configuring in an XML file
Android:clickable= "true"
can be clicked.
However, this situation occurs:
Set XML in TextView
<textview android:id= "@+id/textview1" android:clickable= "false" android:layout_width= "Wrap_ Content " android:layout_height=" wrap_content " android:text=" good study "/>
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 ();}});}}
The result is: Duang. False
Click TextView, the result is: I was clicked true
Guess: for TextView defined Click event, when clicked, will change the value of TextView isclickable, but can be clicked to decide whether it will produce click events, so it will be a bit contradictory. To be solved, the great God who wants to see can give doubts.
The realization and problem summary of Android Marquee