2014-02-12 25 views
0

嗨在我的項目中,我有coverflow小部件。我使用的代碼爲CoverFlow的部件是在這個環節 this is the link i'm using 我想要實現反射那一整部件提前如何在android中顯示coverflow小部件的反射?

感謝

嗨,我是用這種方法,但沒有得到反映,是任何這件事情錯了嗎? for coverflow部件

public boolean createReflectedImages() { 
     // The gap we want between the reflection and the original image 
     System.out.println(" i'm from createReflected image()"); 
     final int reflectionGap = 4;//4 

     int index = 0; 
     for (int imageId : mImageIds) 
     { 
      Bitmap originalImage = BitmapFactory.decodeResource(
        getResources(), imageId); 
      int width = originalImage.getWidth(); 
      int height = originalImage.getHeight(); 
      //int width=100; 
      //int height=100; 

      // This will not scale but will flip on the Y axis 
      Matrix matrix = new Matrix(); 

      //matrix.preScale(-1.0f, 1.0f); 
      //Bitmap mirroredBitmap = Bitmap.createBitmap(originalImage, 0, 0, originalImage.getWidth(), originalImage.getHeight(), matrix, false); 

      matrix.preScale(1, -1); 

      // Create a Bitmap with the flip matrix applied to it. 
      // We only want the bottom half of the image 
      Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, 
        height/2, width, height/2, matrix, false); 

      // Create a new bitmap with same width but taller to fit 
      // reflection 
      Bitmap bitmapWithReflection = Bitmap.createBitmap(width, 
        (height + height/2), Config.ARGB_8888); 

      // Create a new Canvas with the bitmap that's big enough for 
      // the image plus gap plus reflection 
      Canvas canvas = new Canvas(bitmapWithReflection); 
      // Draw in the original image 
      canvas.drawBitmap(originalImage, 0, 0, null); 
      // Draw in the gap 
      Paint deafaultPaint = new Paint(); 
      canvas.drawRect(0, height, width, height + reflectionGap, 
        deafaultPaint); 
      // Draw in the reflection 
      canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, 
        null); 

      // Create a shader that is a linear gradient that covers the 
      // reflection 
    Paint paint = new Paint(); 
    LinearGradient shader = new LinearGradient(0,originalImage.getHeight(), 0,bitmapWithReflection.getHeight() + reflectionGap, 
        0x70ffffff, 0x00ffffff, TileMode.CLAMP); 
      // Set the paint to use this shader (linear gradient) 
      paint.setShader(shader); 
      // Set the Transfer mode to be porter duff and destination in 
      paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); 
      // Draw a rectangle using the paint with our linear gradient 
      canvas.drawRect(0, height, width, 
      bitmapWithReflection.getHeight() + reflectionGap, paint); 

      ImageView imageView = new ImageView(mContext); 
      imageView.setImageBitmap(bitmapWithReflection); 
     android.widget.Gallery.LayoutParams imgLayout = new CoverFlow.LayoutParams(200, 200); 

      imageView.setLayoutParams(imgLayout); 
      imageView.setPadding(50, 100, 50, 20); 
      imageView.setScaleType(ScaleType.MATRIX); 
      mImages[index++] = imageView; 

     } 
     return true; 
+0

這個方法不工作createReflectedImages() – sravani

回答

0

您可以在項目中使用This Coverflow。它使您可以選擇在coverflow中添加反射。我在以前的應用程序

編輯的一個使用這個 - 你所提到的

博客是利用其延伸BaseAdapter適配器和如果你看看源使用createReflectedImages()方法只

的我所提供link代碼,有CoverFlowTestingActivity被其使用以下代碼來設置的CoverFlow有

private void setupCoverFlow(final CoverFlow mCoverFlow, final boolean reflect) { 
    BaseAdapter coverImageAdapter; 
    if (reflect) { 
     coverImageAdapter = new ReflectingImageAdapter(new ResourceImageAdapter(this)); 
    } else { 
     coverImageAdapter = new ResourceImageAdapter(this); 
    } 
    mCoverFlow.setAdapter(coverImageAdapter); 
    mCoverFlow.setSelection(2, true); 
    setupListeners(mCoverFlow); 
} 

在這裏你可以看到,如果我們想要的圖像ReflectingImageAdapter一起選擇在反射與ResourceImageAdapter這是延長AbstractCoverFlowImageAdapter

我認爲這是在上面的鏈接代碼的改變遊戲規則,你

+0

@silver,Thanq您的快速性反應哎兩者都同樣 – sravani

+0

喜同樣的方法我使用的是什麼你指定但沒有得到反思,爲什麼? – sravani

+0

請檢查更新的答案 – silwar

相關問題