0

There is TextView inside RecyclerView(Screen A) and inside a FrameLayout(Screen B), but both have maxLines=10.

In RecyclerView, the textview renders only 10 lines and additional text is ignored.

But the textview in LinearLayout, shows 10 lines but allows the user to scroll.

How to disable scroll and to just show maximum lines set using maxLines.

I have already tried,

  • android:isScrollContainer="false" - it doesn't work

  • android:enabled="false" - it disables the hyperlink clicks in the textview

Update:

I don't want textview in RecyclerView to scroll, I want to disable scrolling in LinearLayout only.

Kamalakannan J
  • 2,818
  • 3
  • 23
  • 51

3 Answers3

1

Tried the below line?

recyclerView.setNestedScrollingEnabled(false);
TheHound.developer
  • 396
  • 1
  • 3
  • 16
1

create a NoScrollTextView extends TextView like this :

public class NoScrollTextView extends TextView {
    public NoScrollTextView(Context context) {
        super(context);
    }

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

    public NoScrollTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public NoScrollTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public void scrollTo(int x, int y) {
        //do nothing
    }
}

Then use this in xml as :

<com.example.NoScrollTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="10"/>
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
1

Just set in class

 TextView tv = (TextView) view.findViewById(R.id.tv);
  tv.setMovementMethod(null);

and in layout

              <TextView
                android:id="@+id/tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:maxLines="8"
                android:text="Lorem Ipsum is simply dummy text of the dummy text of t printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy."
                android:textSize="14sp" />
Dileep Patel
  • 1,988
  • 2
  • 12
  • 26