Android make会在重复模式下继续在单个视图中滚动文本

时间:2013-12-17 11:30:09

标签: android

我正在尝试实施自动收报机,您可以在滚动模式下查看所有自动收报机,查看下图,

enter image description here

现在我想继续滚动例如

在一些空格之后

在@ user5 中,并使用相同的值重新开始,没有像初始空间中那样的空白区域

我想要这样

scrolling text from one user 3 hours @user3   <some space>     scrolling text from...
抱歉英语不好

这是我的代码

            View view = parent_layout.getChildAt(index);
        // measures the unconstrained size of the view
        // before it is drawn in the layout
        view.measure(View.MeasureSpec.UNSPECIFIED,
                View.MeasureSpec.UNSPECIFIED);

        // takes the unconstrained width of the view
        float width = view.getMeasuredWidth();
        float height = view.getMeasuredHeight();

        // gets the screen width

        view.setLayoutParams(new LinearLayout.LayoutParams((int) width,
                (int)height));

        Log.e("contact details","width and screenwidth are" + width + "/"
                + screenWidth + "///" + view.getMeasuredWidth());

        // performs the calculation
        toXDelta = width - (screenWidth - 0);

        // sets toXDelta to -300 if the text width is smaller that the
        // screen size
        if (toXDelta < 0) {
            toXDelta = 0 - screenWidth;// -300;
        } else {
            toXDelta = 0 - screenWidth - toXDelta;// -300 - toXDelta;
        }
//          tickerList.add(view);
//          animList.add(mAnimation);
         // Animation parameters
            mAnimation = new TranslateAnimation(screenWidth,
                    toXDelta, 0, 0);
            mAnimation.setDuration(15000);
//          mAnimation.setRepeatMode(Animation.RESTART);
            mAnimation.setRepeatCount(Animation.INFINITE);
            view.setAnimation(mAnimation);

1 个答案:

答案 0 :(得分:0)

我的解决方案是创建双字符串意味着如果长度低于屏幕宽度并使用Textview中的选取框功能,则将当前字符串附加到自身。

private float screenWidth;

onCreate(){
    TextView tv = (TextView)findViewById(R.id.textview);
    Point outSize = new Point();
    getWindowManager().getDefaultDisplay().getSize(outSize);
    screenWidth = outSize.x;
    StringBuilder ticker = new StringBuilder("This is my String");

    do{
        tv.setText(Html.fromHtml(ticker.toString()));
        int w = ticker.length();
        if(screenWidth>w){
            ticker.append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            ticker.append(tickerList.get(index));
            tv.setText(Html.fromHtml(ticker.toString()));
        }else
            break;
    }while(true);
}

xml代码

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:textSize="18sp"
    android:padding="5dp" 
    android:id="@+id/textView1">

</TextView>