我已經解決了這個問題,卻忘了寫吧:)
我layout.xml
文件看起來像這樣:
<com.handmark.pulltorefresh.library.PullToRefreshScrollView
android:id="@+id/home_info_pulltorefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/home_info_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white_background"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/charts_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
android:paddingRight="5dp" >
<FrameLayout
android:id="@+id/frame_container_chart_top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/frame_container_chart_bottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<FrameLayout
android:id="@+id/frame_container_right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
android:fillViewport="true"
被用來拉伸其內容以填充視口(請滾動match_parent的高度)
我添加包含的ListView片段編程(R.layout.frame_container_right
片段資源ID)
一切工作正常,但當我試圖向下滾動ListView時,我的ScrollView開始滾動。滾動ListView工作正常。另外我注意到,如果我點擊ListView,將手指向左或向右移動,然後嘗試向下滾動,觸摸事件不會從ListView傳輸到ScrollView,並且我會得到預期的行爲。所以我決定以編程方式模擬這種情況:
mListViewReviews.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
long startTime = SystemClock.uptimeMillis();
long duration = 1;
MotionEvent e = MotionEvent.obtain(startTime, startTime + duration, MotionEvent.ACTION_MOVE, event
.getX(), event.getY() + 10, 0);
MotionEvent ev = MotionEvent.obtain(startTime + duration, startTime + duration * 2,
MotionEvent.ACTION_MOVE, event.getX(), event.getY() + 20, 0);
v.dispatchTouchEvent(e);
v.dispatchTouchEvent(ev);
}
return false;
}
});
其結果是,我有工作與適當的單元複用和工作拉來刷新邏輯的ListView。謝謝!
嘿UneXp,我在滾動時面臨同樣的問題,我已經嘗試過你的解決方案,但它不工作:( – Rajan