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?