2

I have a RecyclerView (ytRC) and within that RecyclerView, each element has a thumbnail and a corresponding title that gets inside the RecyclerView via an adapter (ResultsAdapter), which puts the thumbnail and the title into a cardview. I want to make my title in the cardview a single line, which is easy enough. But, some titles are too long, so they get cut off. I thought that a marquee textview would be a great way to fix this, so off I went searching for a solution.

I found some results such as this and this. But, those solutions only partially worked, which means that only 1 out of the 50 elements in the RecyclerView actually scrolled that needed to scroll due to their length. I think this happened because I was calling title.setEnabled(true); and title.requestFocus(); in the onBindViewHolder() method of the ResultsAdapter and the text was only being marqueed when the only a certain view in the RecyclerView was being produced.

Another solution that I wanted to try was to create a custom TextView class ScrollingTextView:

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;


public class ScrollingTextView extends android.support.v7.widget.AppCompatTextView {
public ScrollingTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
}

public ScrollingTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

private void init() {
    //set scrolling
    setSelected(true);
    requestFocus();
}
}

But, using that class yields the same results. So, how would I go about marqueeing a textview in each RecyclerView element that has too much text?

rakeshdas
  • 2,363
  • 5
  • 20
  • 28

1 Answers1

5

Marquee is simple for scrolling long textView

<TextView
   android:text="lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00"
   android:id="@+id/TextView02"
   android:layout_width="200dip"
   android:layout_height="wrap_content"
   android:marqueeRepeatLimit="marquee_forever"
   android:ellipsize="marquee"
   android:singleLine="true"
   android:focusable="true"
   android:inputType="text"
   android:maxLines="1">
</TextView>

And in Program

holder.textView.setSelected(true);

This will aoutomatically scroll the long the text in TextView.

noobEinstien
  • 3,147
  • 4
  • 24
  • 42