1 ,:
2. Core code:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHByZSBjbGFzcz0 = "brush: java;"> package com. example. pic_reflection; import android. app. activity; import android. graphics. bitmap; import android. graphics. bitmap. config; import android. graphics. canvas; import android. graphics. linearGradient; import android. graphics. matrix; import android. graphics. paint; import android. graphics. porterDuff. mode; import android. graphics. porterduxfermode; import android. graph Ics. shader. tileMode; import android. graphics. drawable. bitmapDrawable; import android. OS. bundle; import android. widget. imageView; public class MainActivity extends Activity {private ImageView img = null; private ImageView orginalImg; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); this. orginalImg = (ImageView) this. findV IewById (R. id. img); this. orginalImg. setBackgroundResource (R. drawable. b); this. img = (ImageView) this. findViewById (R. id. reflection1); this. img. setImageBitmap (createReflectedImage (BitmapDrawable) this. getResources (). getDrawable (R. drawable. B )). getBitmap (), 110);} public static Bitmap createReflectedImage (Bitmap originalImage, int reflectionHeight) {int width = originalImage. getWidth (); int height = OriginalImage. getHeight (); Matrix matrix = new Matrix (); // implements the 90-degree matrix for image flip. preScale (1,-1); if (reflectionHeight> height) reflectionHeight = height; // create a reflection image (half the size of the original image) Bitmap reflectionImage = Bitmap. createBitmap (originalImage, 0, height-reflectionHeight, width, reflectionHeight, matrix, false); // create a reflection image Bitmap finalReflection = Bitmap. createBitmap (width, reflectionHeight, Config. ARGB _ 8888); // create a Canvas canvas Canvas = new canvas (finalReflection); // Canvas. drawBitmap (originalImage, 0, 0, null); // draws the reflected image to the canvas. drawBitmap (reflectionImage, 0, 0, null); Paint shaderPaint = new Paint (); // create a linear gradient LinearGradient object LinearGradient shader = new LinearGradient (0, 0, 0, finalReflection. getHeight () + 1, 0x70ffffff, 0x00ffffff, TileMode. MIRROR); shaderPaint. setShader (shader); shaderPaint. SetXfermode (new porterduxfermode (Mode. DST_IN); // draw the area of the reversed image size on the canvas, and add the gradient effect to it. The image reflection effect is displayed. Canvas. drawRect (0, 0, width, finalReflection. getHeight (), shaderPaint); return finalReflection ;}}3. main. xml
4. activity_main.xml
<FrameLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "wrap_content" android: layout_height = "wrap_content">
</FrameLayout>