Autoscrollable TextView in ViewPager. How to slide to next page?

244 views Asked by At

I have a ViewPager with autoscrollable TextView inside of it. When I slide to see the next page, instead of sliding, detects the event as a scroll of the TextView.

How can I avoid this?

<TextView
    android:gravity="center_horizontal"
    android:id="@+id/main_card_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="30sp"
    android:textColor="@color/black"
    android:ellipsize="marquee" />

Then, in my Java code I do:

tvName.setSingleLine(true);
tvName.setSelected(true);

And this TextView is in a page of a ViewPager. When I slide the page to go to the next page, instead of this what happens is that behaves like if I was doing scroll inside of the TextView.

1

There are 1 answers

1
Vij On

you can disable autoscroll event of textview ontouch event .

 TextView lv = (TextView) findViewById(R.id.tv);

 lv.setOnTouchListener(new OnTouchListener() {

   @Override
   public boolean onTouch(View v, MotionEvent event) {
  // Disallow the touch request for parent scroll on touch of child view
   v.getParent().requestDisallowInterceptTouchEvent(true);
    return false;
 }

 });