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.
To achieve this effect, you must add the following in the layout file:
android:singleLine=”true”android:ellipsize=”marquee”android:focusableInTouchMode=”true”android:focusable=”true”
Note: layout_width = "" must be written as a fixed value. It cannot be wrap_content or fill_parent, and it must be longer than the text length. You can also set the number of scrolling times. Android: marqueerepeatlimit = "";
Android: marqueerepeatlimit = "marquee_forever" indicates rolling.
However, this type of Marquee can only be rolled when the control gets the focus. To keep the content in the control rolling, you must customize the control and rewrite the three methods:
package cn.etzmico.marqueetest;import android.content.Context;import android.graphics.Rect;import android.util.AttributeSet;import android.widget.Button;public class MarqueeButton extends Button {public MarqueeButton(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}@Overrideprotected void onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect) {// TODO Auto-generated method stubif(focused)super.onFocusChanged(focused, direction, previouslyFocusedRect);}@Overridepublic void onWindowFocusChanged(boolean hasWindowFocus) {// TODO Auto-generated method stubif(hasWindowFocus)super.onWindowFocusChanged(hasWindowFocus);}@Overridepublic boolean isFocused() {return true;}}
The following figure shows how to use this control in the layout file:
<cn.easymobi.application.memorytest.MarqueeButtonandroid:layout_width=”216dip”android:layout_height=”wrap_content”android:id=”@+id/btSecond”android:background=”@drawable/button_test2″android:layout_marginTop=”15dip”android:text=”@string/calculate”android:ellipsize=”marquee”android:gravity=”center”android:textColor=”@color/white”android:textStyle=”bold”android:focusable=”true”android:marqueeRepeatLimit=”marquee_forever”android:focusableInTouchMode=”true”android:scrollHorizontally=”true”android:singleLine=”true”android:paddingLeft=”50dip”android:paddingRight=”50dip”android:textSize=”20dip”/>