コード例 #1
0
  /**
   * Creates the reflected images.
   *
   * @return true, if successful
   */
  private void createReflectedImages() {

    final int width = this.wrappedViewBitmap.getWidth();
    final int height = this.wrappedViewBitmap.getHeight();

    final Matrix matrix = new Matrix();
    matrix.postScale(1, -1);

    final int scaledDownHeight = (int) (height * originalScaledownFactor);
    final int invertedHeight = height - scaledDownHeight - reflectionGap;
    final int invertedBitmapSourceTop = scaledDownHeight - invertedHeight;
    final Bitmap invertedBitmap =
        Bitmap.createBitmap(
            this.wrappedViewBitmap,
            0,
            invertedBitmapSourceTop,
            width,
            invertedHeight,
            matrix,
            true);

    this.wrappedViewDrawingCanvas.drawBitmap(
        invertedBitmap, 0, scaledDownHeight + reflectionGap, null);

    final Paint paint = new Paint();
    final LinearGradient shader =
        new LinearGradient(
            0,
            height * imageReflectionRatio + reflectionGap,
            0,
            height,
            0x70ffffff,
            0x00ffffff,
            Shader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    this.wrappedViewDrawingCanvas.drawRect(
        0, height * (1 - imageReflectionRatio), width, height, paint);
  }
コード例 #2
0
  @SuppressLint("DrawAllocation")
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    if (changed) {
      int measuredWidth = this.getMeasuredWidth();
      int measuredHeight = this.getMeasuredHeight();

      if (this.wrappedViewBitmap == null
          || this.wrappedViewBitmap.getWidth() != measuredWidth
          || this.wrappedViewBitmap.getHeight() != measuredHeight) {
        this.wrappedViewBitmap =
            Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
        this.wrappedViewDrawingCanvas = new Canvas(this.wrappedViewBitmap);
      }

      View child = getChildAt(0);
      int childWidth = child.getMeasuredWidth();
      int childHeight = child.getMeasuredHeight();
      int childLeft = (measuredWidth - childWidth) / 2;
      int childRight = measuredWidth - childLeft;
      child.layout(childLeft, 0, childRight, childHeight);
    }
  }