LOADING...
03 Feb

Prevent Android TextView scrolling is resetted on an update of a different TextView

Basically the scroll animation on an Android TextView with horizontally automatic scroll (ellipsize marquee) is reset every time something changes in the layout in which they are placed on the text folder (MATCH_PARENT or WRAP_CONTENT).
To prevent the reset does not happen you can specify fixed size or take out the TextView from layout where it dipends from content adaptation.
An simple example of code:
TextView scrollertext = new TextView(this);
scrollertext.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
scrollertext.setSingleLine(true);
scrollertext.setHorizontallyScrolling(true);
scrollertext.setFocusable(true);
scrollertext.setFocusableInTouchMode(true);
scrollertext.setMarqueeRepeatLimit(-1);
scrollertext.setEllipsize(TextUtils.TruncateAt.MARQUEE);
scrollertext.setSelected(true);

//the most important!!!!!
scrollertext.post(new Runnable() {
@Override
public void run() {
scrollertext.setLayoutParams(new LinearLayout.LayoutParams(scrollertext.getWidth(), scrollertext.getHeight()));
}
});