我有自定义画廊.
图库表示框架布局的项目.
它上面有一个imageView和textView.
图库表示框架布局的项目.
它上面有一个imageView和textView.
如果textView中的文本太长,我需要它自动滚动.
它是一行文本,需要水平滚动.
我发现了这段代码:
TextView
android:text="Single-line text view that scrolls automatically"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
它适用于我的测试应用程序,其中只有一个文本视图.
但它在我的画廊中不起作用.注意到,文字只是保持不动.
有帮助吗?
解决方法
试试这个自定义TextView类:
public class AutoScrollingTextView extends TextView {
public AutoScrollingTextView(Context context,AttributeSet attrs,int defStyle) {
super(context,attrs,defStyle);
}
public AutoScrollingTextView(Context context,AttributeSet attrs) {
super(context,attrs);
}
public AutoScrollingTextView(Context context) {
super(context);
}
@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);
}
}
@Override
public boolean isFocused() {
return true;
}
}
并设置以下XML属性:
android:scrollHorizontally="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
这在我的词典应用程序中非常有效,其中多个条目可能需要同时自动滚动以显示完整内容.