TextView marquee not scrolling

795 views Asked by At

I spent hours trying and googling. I have looked at other posts and nothing worked. I do have tv.setSelected(true); in my code

`

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.bottom, container, false);
    TextView tv = (TextView)v.findViewById(R.id.tv);
    tv.setText(R.string.very_long);
    tv.setSelected(true);

    return v;
}

`

this is my textView

<TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:freezesText="true"
    android:marqueeRepeatLimit="marquee_forever"
    android:paddingLeft="15dip"
    android:paddingRight="15dip"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:textSize="30sp" />
2

There are 2 answers

0
krishnan muthiah pillai On

place [tv.setSelected(true);] below to setContentView(R.layout.activity_main);

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    text=(TextView)findViewById(R.id.textView2);
    text.setText("Long Text ....................!");
    text.setSelected(true);

in xml

   <TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text=""
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:singleLine="true" />
0
Jay Rathod On

Just Do Like This in Your OnCreate Method.

    yourTextView= (TextView) findViewById(R.id.yourTextViewID);

    yourTextView.setSelected(true);
    yourTextView.setEllipsize(TruncateAt.MARQUEE);
    yourTextView.setSingleLine(true);