2011-09-19 83 views
1

我讓我的圖像至少滾動,但我不想滾動圖片本身。我有變量稱爲maxLeft,maxRight,等我有,我現在正好被設置爲可滾動的ImageView Android問題(overscrolling)

ImageView img = (ImageView)findViewById(R.id.mapimg); 
    DisplayMetrics dm = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(dm); 

    int maxX = (int)????; 
    int maxY = (int)????; 

    // set scroll limits 
    final int maxLeft = (maxX * -1); 
    final int maxRight = maxX; 
    final int maxTop = (maxY * -1); 
    final int maxBottom = maxY; 

我一直在用我所能取代問號的我放在那裏瞎搞,但我似乎卡住了,特別是當我嘗試使用不同的模擬器時。任何幫助真的會很感激!謝謝

回答

1

如果我正確理解你的問題,你想擴展ImageView添加滾動。如果是這樣的話,您不想使用getWindowmanager(),因爲它會返回整個屏幕的尺寸(包括標題欄)。相反,您想擴展ImageView並從onMeasure獲取視圖的尺寸。您可以查看我的回答here,其中我添加了縮放功能並平移到ImageView。

我用setImageMatrix和postTranslate設置一個矩陣等於圖像並移動它。爲了跟蹤圖像的位置,我使用了以下內容:

float f[] = new float[9]; 
matrix.getValues(m); //see matrix documentation. inserts matrix values into f. 
float x = m[Matrix.MTRANS_X]; 
float y = m[Matrix.MTRANS_Y]; 

浮點x和y將跟蹤圖像的左上角。確保下一個事件是否會導致圖像滾動出界,您將postTranslate調整爲等於圖像的邊界。我上面鏈接的答案應該給你一個開始的好地方,如果你還想要縮放功能,那麼你很幸運,因爲你不必做任何額外的工作。