2012-05-15 4 views
2

Android Coverflow 샘플을 구현했습니다. 이미지를 클릭하면 위치를 검색하고 ImageView에 이미지를 표시 할 수 있습니다. 내 다른 요구 사항은 을 전달할 때의 이미지에 초점을 맞 춥니 다. 초점을 맞춘 이미지를 중심으로 가져와야합니다. 변형 도중 이미지 사이의 각도를 계산하는 코드입니다. 필요한 출력을 얻으려면 어떻게 변경합니까?Android Coverflow - 위치가 알려진 이미지에 초점 맞추기

protected boolean getChildStaticTransformation(final View child, final Transformation t) { 

    final int childCenter = getCenterOfView(child); 
    final int childWidth = child.getWidth(); 
    int rotationAngle = 0; 

    t.clear(); 
    t.setTransformationType(Transformation.TYPE_MATRIX); 

    if (childCenter == mCoveflowCenter) { 
     transformImageBitmap((ImageView) child, t, 0); 
    } else { 
     rotationAngle = (int) ((float) (mCoveflowCenter - childCenter)/childWidth * mMaxRotationAngle); 
     if (Math.abs(rotationAngle) > mMaxRotationAngle) { 
      rotationAngle = rotationAngle < 0 ? -mMaxRotationAngle : mMaxRotationAngle; 
     } 
     transformImageBitmap((ImageView) child, t, rotationAngle); 
    } 

    return true; 
} 


private void transformImageBitmap(final ImageView child, final Transformation t, final int rotationAngle) { 
    mCamera.save(); 
    final Matrix imageMatrix = t.getMatrix(); 

    final int height = child.getLayoutParams().height; 

    final int width = child.getLayoutParams().width; 
    final int rotation = Math.abs(rotationAngle); 

    mCamera.translate(0.0f, 0.0f, 100.0f); 

    // As the angle of the view gets less, zoom in 
    if (rotation < mMaxRotationAngle) { 
     final float zoomAmount = (float) (mMaxZoom + rotation * 1.5); 
     mCamera.translate(0.0f, 0.0f, zoomAmount); 
    } 

    mCamera.rotateY(rotationAngle); 
    mCamera.getMatrix(imageMatrix); 
    imageMatrix.preTranslate(-(width/2.0f), -(height/2.0f)); 
    imageMatrix.postTranslate((width/2.0f), (height/2.0f)); 
    mCamera.restore(); 
} 

답변

0

당신은 커버 플로우의 setOnItemSelectedListener를 사용하여이 작업을 수행 할 수 있습니다. 센터 이미지의 위치를 ​​얻을 코드는 아래를 참조하십시오.

int sel_pos; 

coverFlow.setOnItemSelectedListener(new SelectListener(this)); 

    private class SelectListener implements AdapterView.OnItemSelectedListener { 

      public SelectListener(Context c) 
      { 

      } 

      public void onItemSelected(AdapterView<?> parent, View v, int position,long id) 
      { 

       Log.e("Changed----->", "" + position); 

       // Zoom the new selected view 
       try 
       {        
        sel_pos = position;    
        coverImageAdapter.notifyDataSetChanged(); 

       } catch (Exception animate) 
       { 

       }  

      } 

      public void onNothingSelected(AdapterView<?> parent) { 
      } 

     } 

이제 어댑터의 getview 메소드에서 coverFlow의 이미지 초점을 변경할 수 있습니다.

public View getView(int position, View convertView, ViewGroup parent) 
    { 
     // Use this code if you want to load from resources 
     ImageView i = new ImageView(mContext); 
     i.refreshDrawableState(); 
     Log.e("position==", ""+position); 

     if(sel_pos==position) 
     { 
      i.setImageResource(selectedImage[position]); 
     } 
     else 
     { 
      i.setImageResource(UnselectedImage[position]); 

     }  


     i.setLayoutParams(new CoverFlow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
     i.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 


     // Make sure we set anti-aliasing otherwise we get jaggies 
     BitmapDrawable drawable = (BitmapDrawable) i.getDrawable(); 
     drawable.setAntiAlias(true); 
     return i; 

    } 

홉 이것은 도움이 될 것입니다.