I just implemented "Pull to Refresh" to my code today and had a little problem. While scrolling the lyrics up, the pull to refresh (PTR) action occurs. I would like to disable that while the user touches on the lyricsTextView
, or rather the whole space around that TextView
. I have the title shown above the lyricsTextView
which will not be scrollable.
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainScrollView">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/playerFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:tag="playerFragment">
<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="title"
android:textSize="25sp"
android:theme="@style/AppTheme" />
<TextView
android:id="@+id/artistTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTextView"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="artist"
android:textSize="20sp" />
<ImageView
android:id="@+id/albumImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@id/artistTextView"
android:alpha="76"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/artistTextView"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lyricsScrollView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:layout_marginLeft="7dip"
android:layout_marginRight="7dip"
android:layout_marginTop="7dip">
<TextView
android:id="@+id/lyricsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:maxLines="999999"
android:scrollbars="vertical"
android:text="lyrics/>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
I tried using this code which I found on StackOverFlow but wasn't able to accomplish what I want.
playerFragment.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
lyricsScrollView.setOnTouchListener(new View.OnTouchListener() {
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;
}
});
screenshot:
https://dl.dropboxusercontent.com/u/36670712/Screenshot_2015-02-15-00-40-26%5B1%5D.png