TextView实现跑马灯效果源码
如题,<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.and...
如题,<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<LinearLayout
android:layout_height="100.0dp"
android:layout_width="100.0dp"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:text="谁校对时间,谁就会突然老去。"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
scrollHorizontally="true"
marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"/>
</LinearLayout>
</LinearLayout>
我用这个制成了一个小软件,可以跑马灯,但是把它放在其他软件中,跑了几次就不跑了,并且一拉下下拉栏就会停止滚动, 展开
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<LinearLayout
android:layout_height="100.0dp"
android:layout_width="100.0dp"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:text="谁校对时间,谁就会突然老去。"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
scrollHorizontally="true"
marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"/>
</LinearLayout>
</LinearLayout>
我用这个制成了一个小软件,可以跑马灯,但是把它放在其他软件中,跑了几次就不跑了,并且一拉下下拉栏就会停止滚动, 展开
1个回答
展开全部
用自定义的TextView
public class AlwaysMarqueeTextView extends TextView {
public AlwaysMarqueeTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AlwaysMarqueeTextView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
return true;
}
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
if (focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean focused) {
if (focused)
super.onWindowFocusChanged(focused);
}
}
xml
<com.example.AlwaysMarqueeTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="这里是天翔灯饰的公告内容....运用文字跑马灯效果....运用文字跑马灯效果....运用文字跑马灯效果....运用文字跑马灯效果....运用文字跑马灯效果....运用文字跑马灯效果" />
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询