2016-09-04 3 views
0

私はTouchImageViewからViewPagerを使用して画像をアプリケーションにロードしています。これは画像の読み込みを担当するです。カスタムイメージビューで画像を一番上に整える

float redundantXSpace = viewWidth - (scaleX * drawableWidth); 
     float redundantYSpace = viewHeight - (scaleY * drawableHeight); 
     matchViewWidth = viewWidth - redundantXSpace; 
     matchViewHeight = viewHeight - redundantYSpace; 
     if (!isZoomed() && !imageRenderedAtLeastOnce) { 
      // 
      // Stretch and center image to fit view 
      // 
      matrix.setScale(scaleX, scaleY); 
      matrix.postTranslate(redundantXSpace/2, redundantYSpace/2); 
      normalizedScale = 1; 

     } else { 
      // 
      // These values should never be 0 or we will set viewWidth and viewHeight 
      // to NaN in translateMatrixAfterRotate. To avoid this, call savePreviousImageValues 
      // to set them equal to the current values. 
      // 
      if (prevMatchViewWidth == 0 || prevMatchViewHeight == 0) { 
       savePreviousImageValues(); 
      } 

      prevMatrix.getValues(m); 

コードは、縦の中心に画像を読み込みます。私が達成したいのは、垂直上にイメージをロードすることです。 matchViewHeight = viewHeight - redundantYSpace;matchViewHeight = viewHeight;に変更すると、画像全体の高さが表示されます。垂直上に整列させるためにどのような変更を行う必要がありますか?

答えて

1

使用

matrix.setScale(scaleX, scaleY); 
matrix.postTranslate(redundantXSpace/2, 0); 

postTranslate - 画像を移動させます。上揃えのためにy軸に沿って移動する必要はありません。

下部に整列するために

matrix.setScale(scaleX, scaleY); 
matrix.postTranslate(redundantXSpace/2, redundantYSpace); 
+0

おかげで、しかし、 'ViewPager'をスライド上のこの唯一の作品。私はそれをスライドから解放した後、画像は垂直方向の中心に戻る。 – user2872856

+0

メソッド 'setZoom(float scale、float focusX、float focusY、ScaleType scaleType)で置き換えを試みてください。 \t m [Matrix.MTRANS_Y] = - ((focusY * getImageHeight()) - (viewHeight * 0.5f));' 'm [Matrix.MTRANS_Y] = 0;'にあります。行列を変更した場所を確認してください。 – KosWarm

+0

まだ動作しません。コードは複雑なようです。とにかく、私はあなたに感謝の意を表します。 – user2872856

関連する問題