Avoid scrolling reset (marquee ellipsize) on Android TextView
This post taken from stack overflow is very very useful to save a lot of time and coding!
The problem is that the horizontal scroll animation on an Android TextView in mode ellipsize marquee is reset every time in the containing layout something changes when a relative size is set on the TextView (MATCH_PARENT and/or WRAP_CONTENT).
If we specify fixed size the reset does not happens, how to do?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
TextView tv = new TextView(this); tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)); tv.setSingleLine(true); tv.setHorizontallyScrolling(true); tv.setFocusable(true); tv.setFocusableInTouchMode(true); tv.setMarqueeRepeatLimit(-1); tv.setEllipsize(TextUtils.TruncateAt.MARQUEE); tv.setSelected(true); //the most important!!!!! tv.post(new Runnable() { @Override public void run() { tv.setLayoutParams(new LinearLayout.LayoutParams(tv.getWidth(), tv.getHeight())); } }); |