Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3> First Step</h3> <p>Create a drawable like below.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item&gt;&lt;layer-list&gt; &lt;item android:left="3dp" android:top="3dp"&gt;&lt;shape&gt; &lt;gradient android:angle="270" android:endColor="#E2E2E2" android:startColor="#BABABA" /&gt; &lt;stroke android:width="3dp" android:color="#BABABA" /&gt; &lt;corners android:radius="2dp" /&gt; &lt;padding android:bottom="3dp" android:left="2dp" android:right="3dp" android:top="2dp" /&gt; &lt;/shape&gt;&lt;/item&gt; &lt;/layer-list&gt;&lt;/item&gt; &lt;/selector&gt; </code></pre> <h3> Second Step</h3> <p>Set it as background of <code>ImageView</code></p> <pre><code>&lt;ImageView .. android:background="@drawable/selected_image_shadow" &gt; &lt;/ImageView&gt; </code></pre> <p><strong>Output</strong></p> <p><img src="https://i.stack.imgur.com/AENYb.png" alt="enter image description here"></p> <p>Left image is without shadow and right image is with shadow. </p> <p><strong>Note</strong></p> <p>You need to modify code as per your requirement. This is sample demo with my requirement. </p> <p><strong>Edit</strong></p> <p>Use following code to apply reflection effect on image.</p> <pre><code>public static Bitmap applyReflection(Bitmap originalImage) { // gap space between original and reflected final int reflectionGap = 4; // get image size int width = originalImage.getWidth(); int height = originalImage.getHeight(); // this will not scale but will flip on the Y axis Matrix matrix = new Matrix(); 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 defaultPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint); // 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); return bitmapWithReflection; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload