【发布时间】:2015-02-14 15:50:48
【问题描述】:
我今天刚刚在我的代码中实现了“Pull to Refresh”,但遇到了一个小问题。向上滚动歌词时,会发生拉动刷新 (PTR) 操作。我想在用户触摸lyricsTextView,或者更确切地说是TextView 周围的整个空间时禁用它。我在lyricsTextView 上方显示的标题不可滚动。
<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>
我尝试使用在 StackOverFlow 上找到的这段代码,但无法完成我想要的。
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;
}
});
截图:
https://dl.dropboxusercontent.com/u/36670712/Screenshot_2015-02-15-00-40-26%5B1%5D.png
【问题讨论】:
-
能否请您链接到您在哪里找到此代码的堆栈溢出问题?
-
@CurlyCorvus 给你:stackoverflow.com/questions/15062365/…
标签: android textview scrollview ontouchlistener