How to reverse the direction of marquee of a TextView

前端 未结 8 950
孤城傲影
孤城傲影 2020-11-30 05:16

I want to reverse the direction of marquee in the TextView. By default, the text moves from Right to Left, I want it to move from Left to Right. How can I do this?

8条回答
  •  一个人的身影
    2020-11-30 05:50

    For right to left text for every one to use: try this:

            TextView tv = (TextView) findViewById(R.id.txt);
        Rect bounds = new Rect();
        Paint textPaint = tv.getPaint();
        String text = tv.getText().toString();
        textPaint.getTextBounds(text, 0, text.length(), bounds);
        int width = bounds.width();
        LinearLayout.LayoutParams lp = (LayoutParams) tv.getLayoutParams();
        lp.width = width + 100;
                int startX = 300;
        TranslateAnimation ta = new TranslateAnimation(startX, lp.width, 0, 0);
        ta.setDuration(20000);
        ta.setRepeatCount(-1);
        tv.setAnimation(ta);
    

提交回复
热议问题