我在这里遇到一个奇怪的问题,ScrollView
只滚动一次的正常问题,但在我的情况下,它会一直滚动并滚动到底部。
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/search"
android:src="@drawable/ic_search"
android:layout_gravity="end"/>
</FrameLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollview"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.daimajia.slider.library.SliderLayout
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="@dimen/slider_height"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/home_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_marginTop="@dimen/slider_rv_margin"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
代码:
mScrollView = (ScrollView) mView.findViewById(R.id.scrollview);
mRecyclerView.setNestedScrollingEnabled(false);
mRecyclerView.addOnScrollListener(new EndlessRecyclerViewScrollListener(mGridLayout) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
Log.i("Scroller","Scrolling: Page " + page + " - Total: " + totalItemsCount);
mCurrentPage = mCurrentPage + 1;
GetArticles(false);
}
});
日志不断被调用,例如:
10-06 15:55:33.027 794-794/com.testapp I/Scroller: Scrolling: Page 4 - Total: 16
10-06 15:55:33.639 794-794/com.testapp I/Scroller: Scrolling: Page 5 - Total: 20
10-06 15:55:34.264 794-794/com.testapp I/Scroller: Scrolling: Page 6 - Total: 24
10-06 15:55:34.895 794-794/com.testapp I/Scroller: Scrolling: Page 7 - Total: 28
10-06 15:55:35.573 794-794/com.testapp I/Scroller: Scrolling: Page 8 - Total: 32
10-06 15:55:36.311 794-794/com.testapp I/Scroller: Scrolling: Page 9 - Total: 36
10-06 15:55:36.923 794-794/com.testapp I/Scroller: Scrolling: Page 10 - Total: 40
10-06 15:55:37.513 794-794/com.testapp I/Scroller: Scrolling: Page 11 - Total: 44
答案 0 :(得分:1)
什么是EndlessRecyclerViewScrollListener? 它应该是OnScrollListener吗? 这可能会导致问题。
答案 1 :(得分:0)
使用<android.support.v4.widget.NestedScrollView>
代替<ScrollView>