使用网格布局(GridView)在内部使用EditText控件,出现当输入过长后,使用按钮跳转横向宽度变大无法解决。
实现跑马灯效果
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
实现无数次滚动
android:marqueeRepeatLimit="marquee_forever"
动态设置textview获取焦点,永远的跑马灯(支持多个)
@Override
public boolean isFocused() {
return true;
}
@Override
protected void onFocusChanged(boolean focused , int direction , Rect previouslyFocusedRect){
super.onFocusChanged(true,direction,previouslyFocusedRect);
}
跑马灯控制速度和控制方向(以及对于文字数量小于文本宽度情况下解决跑马灯输出),设置方向bool类型函数
后续使用scrollTo(int, int)方法实现不断更新位置
@Override
public void run() {
if(textWidth<xWidth) {
if (lr) {
currentX -= myspeed;
if (currentX < 0) {
if (Math.abs(currentX) >= xWidth) {
currentX = textWidth;
}
}
scrollTo(currentX,0); //更新
}
else{
currentX += myspeed;
if(currentX >= textWidth) {
currentX = -xWidth;
}
scrollTo(currentX,0);
System.out.println("textWidth"+textWidth);
}
}
else {
if (lr) {
currentX -= myspeed;
if (currentX < 0) {
if (Math.abs(currentX) >= textWidth) {
currentX = xWidth;
}
}
scrollTo(currentX,0);
}
else{
currentX += myspeed;
if(currentX >= textWidth) {
currentX = -xWidth;
}
scrollTo(currentX,0);
}
}
invalidate();
postDelayed(this, 5);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isMeasure) {
textWidth = (int) getPaint().measureText(myContext);
xWidth = getWidth();
isMeasure = false;
}
}