找到了解決方法。這太可怕了,但它很有用。
首先,畫廊的代碼負責我的問題的一部分是這樣的:
public boolean onDown(MotionEvent e) {
// Kill any existing fling/scroll
mFlingRunnable.stop(false);
// Get the item's view that was touched
mDownTouchPosition = pointToPosition((int) e.getX(), (int) e.getY());
if (mDownTouchPosition >= 0) {
mDownTouchView = getChildAt(mDownTouchPosition - mFirstPosition);
mDownTouchView.setPressed(true);
}
// Reset the multiple-scroll tracking state
mIsFirstScroll = true;
// Must return true to get matching events for this down event.
return true;
}
更準確地說這條線:
mDownTouchView.setPressed(true);
這裏按我的幻燈片的版式和默認LinearLayout的setPressed行爲會將其分派給所有兒童,以便按下所有兒童。
首先我試圖使畫廊的一個子類,並覆蓋onDown。如果我只是返回了虛假而沒有其他的東西,它就可以工作,但幻燈片在接觸時會跳到下一張幻燈片中。那是因爲這一行:
mFlingRunnable.stop(false);
哪一個沒執行。由於該變量是私有的,並且與Gallery類中的所有其他變量相關,所以我沒有找到從子類中使用它的方法。我試圖複製所有的圖庫代碼,但它也沒有工作,因爲它使用了很多隻有包訪問的東西......等等。
所以我創建了LinearLayout的子類,它覆蓋onSetPressed:
public class LinearLayoutOnSetPressedDoNothing extends LinearLayout {
public LinearLayoutOnSetPressedDoNothing(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setPressed(boolean pressed) {
}
}
和使用,在我的佈局,而不是的LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<com.test.LinearLayoutOnPressDoNothing
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- content -->
</com.test.LinearLayoutOnPressDoNothing>
和好,這個工程。
來源
2012-06-05 15:06:55
Ixx