1

使用MikeOrtiz TouchImageView從GitHub中移除。下面是我米試圖設置寬度適合只 此屏幕在橫向鏈接TouchImageView如何在橫向方向上使用TouchImageView設置適合屏幕的寬度(使用TouchImageView)android

  • 是爲了展示我想要做的圖像。

  • 我想這

Landscape width fit to screen

  • 取而代之的是,我米的景觀 landscape width not fit to screes

現在越來越下面是一些代碼。

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
    viewWidth = MeasureSpec.getSize(widthMeasureSpec); 
    viewHeight = MeasureSpec.getSize(heightMeasureSpec); 

    // 
    // Rescales image on rotation 
    // 
    if (oldMeasuredHeight == viewWidth && oldMeasuredHeight == viewHeight 
      || viewWidth == 0 || viewHeight == 0) 
     return; 
    oldMeasuredHeight = viewHeight; 
    oldMeasuredWidth = viewWidth; 

    if (saveScale == 1) { 
     // Fit to screen. 
     float scale; 

     Drawable drawable = getDrawable(); 
     if (drawable == null || drawable.getIntrinsicWidth() == 0 
       || drawable.getIntrinsicHeight() == 0) 
      return; 
     int bmWidth = drawable.getIntrinsicWidth(); 
     int bmHeight = drawable.getIntrinsicHeight(); 

     Log.d("bmSize", "bmWidth: " + bmWidth + " bmHeight : " + bmHeight); 

     float scaleX = (float) viewWidth/(float) bmWidth; 
     float scaleY = (float) viewHeight/(float) bmHeight; 
     scale = Math.min(scaleX, scaleY); 
     matrix.setScale(scale , scale); 

     // Center the image 
     float redundantYSpace = (float) viewHeight 
       - (scale * (float) bmHeight); 
     float redundantXSpace = (float) viewWidth 
       - (scale * (float) bmWidth); 
     redundantYSpace /= (float) 2; 
     redundantXSpace /= (float) 2; 

     matrix.postTranslate(redundantXSpace, redundantYSpace); 

     origWidth = viewWidth - 2 * redundantXSpace; 
     origHeight = viewHeight - 2 * redundantYSpace; 
     setImageMatrix(matrix); 
    } 
    fixTrans(); 
} 

謝謝

+0

基本上我不得不改變我的ImageView的放大的方向變化,所以應該適合於屏幕寬度明智的。但不知道如何:( –

回答

0

你必須爲你landsacpe模式要在資源佈局,土地建立一個文件夾,然後在其中創建具有相同名稱的一個XML文件,並設置用戶界面爲你

的偉大工程

如果您將home.xml放在佈局端口文件夾中,那麼當您的設備處於縱向方向時,它將使用文件:layout-port/home.xml。

如果您將home.xml放在layout-land文件夾中,那麼當您的設備處於橫向模式時,它將使用文件:layout-land/home.xml。

對於像縱向和橫向等不同方向模式的含義...我們使用兩個home.xml文件;一個在佈局端口,另一個在佈局域。另一方面,如果您想爲兩者使用相同的佈局文件,則可以將home.xml放在佈局文件夾中,並將其從layout-land和layout-port中移除。

refer this link

+0

感謝您的回覆。但它不工作。基本上我必須改變我的ImageView的方向變化的縮放,以便它適合屏幕寬度明智。但不知道如何: ( –

相關問題