1

저는 MikeOrtiz TouchImageView을 사용하고 있습니다. GitHub에서. 여기 만 여기에 가로 방향의 화면으로 폭에 맞게 설정하려고 해요 링크 TouchImageView안드로이드에서 가로 방향 (TouchImageView 사용)의 화면 너비를 맞추는 방법

  • 내가하고 싶은 것을 보여줄 수있는 이미지입니다.

  • 은 내가 여기에 몇 가지 코드 대신에 내가 landscape width not fit to screes

풍경 지금 받고있어 어떤이의이

Landscape width fit to screen

  • 를 원한다.

    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

기본적으로 내가 그것을 현명 화면 너비에 맞게해야 있도록 방향 변경에 내 이미지 뷰의 확대를 변경해야합니다. 그러나 모르겠다 :( –

답변

0

당신은 당신이 Landsacpe에는 모드에서 원하는 당신

위대한 작품 UI를 고해상도 레이아웃 땅에 하나 개의 폴더를 생성 한 다음에 같은 이름을 가진 하나 개의 XML 파일을 생성하고 설정되어

layout-port 폴더에 home.xml을 넣으면 장치가 세로 방향 일 때 layout-port/home.xml 파일을 사용합니다.

layout-land 폴더에 home.xml을 넣은 경우, 장치가 가로 방향 인 경우 layout-land/home.xml 파일을 사용합니다.

세로 및 가로와 같은 다른 방향 모드의 의미 ... 우리는 두 개의 home.xml 파일을 사용합니다. 하나는 레이아웃 포트에, 다른 하나는 레이아웃 랜드에 있습니다. 반면에 두 레이아웃에 동일한 레이아웃 파일을 사용하려면 layout.xml에 home.xml을 넣고 layout-land 및 layout-port에서 제거하십시오.

refer this link

+0

답장을 보내 주셔서 감사합니다.하지만 작동하지 않습니다. 기본적으로 방향 변경 내 ImageView Zoom 변경해야합니다 그래서 그것을 화면 너비 현명한 맞게해야합니다. 그러나 어떻게 : ( –