Marquee in android
In my android application i need to scroll a marquee text continuously. in my Xml i have this code:
<TextView
android:id="@+id/widget28"
android:layout_width="wrap_content"开发者_JAVA技巧
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use RelativeLayout " />
And in my Java source code i have:
TextView tv = (TextView )findViewById(R.id.widget28);
tv.setSelected(true);
Now my issue is this code works fine and marquee runs fine even if the focus is not on the control but the scrolling of text is not complete.I need the text to scroll completely.If i add space to the text both before and after the text it works fine but that is not good programming. Is there a good way to this?
If you want it to scroll continuously, you must use this in your xml:
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:selectAllOnFocus="true"
android:singleLine="true"
It is not necessary to put setSelected(true); in the file
PS. You must only click on it when the focus changes.
try this::
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use RelativeLayout "
android:focusable="true"
android:focusableInTouchMode="true" android:freezesText="true"></TextView>
Guys, TextView scrolls its text ONLY when it's focused. As soon as it loses the focus, text scrolling will stop.
I don't understand your issue.
I have copied your code and inserted the TextView
in a RelativeLayout
with fill_parent
for the 2 axes and it works fine (isn't that what you want?) :
I have tested that code on default emulator 2.1 and 2.2. No trouble.
Here is my class :
public class TextViewMarquee extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textview);
findViewById(R.id.widget28).setSelected(true);
}
}
And the associated xml :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/widget28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Simple application that shows how to use RelativeLayout"
android:textColor="#ff4500" />
</RelativeLayout>
And that's actually all, no mystery line in the manifest or style or ...
精彩评论